舒尔特方格
<script>
window.onload=function(){
var list = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25];
var new_list = [];
while(true){
if(list.length == 0){
break;
}
var num = parseInt(Math.random()*25+1,10);
var index = list.indexOf(num);
if(index == -1){
continue;
}
list.splice(index,1);
new_list.push(num);
}
var table = document.getElementById("table");
var index = 0;
for(var i=0;i<5;i++){
var tr = document.createElement("tr");
for(var j=0;j<5;j++){
var td = document.createElement("td");
var num = document.createTextNode(new_list[index]);
var button = document.createElement("button");
var font = document.createElement("font");
font.setAttribute("size",10);
font.appendChild(num);
button.appendChild(font);
button.setAttribute("value",new_list[index]);
button.setAttribute("style","height:100px;100px");
td.appendChild(button);
td.setAttribute("align","center");
button.setAttribute("onclick","clickEvent(this)");
tr.appendChild(td);
index ++;
}
table.appendChild(tr);
}
}
var arrary = [];
var time_array = [];
function clickEvent(obj){
var num = parseInt(obj.getAttribute("value"));
if(arrary.length == 0 && num != 1){
alert("失败!");
return
}
if(num == 1){
arrary.push(num);
var myDate = new Date();
var begin = myDate.getSeconds();
time_array.push(begin);
}else{
if(num==25 && arrary.length==24){
var myDate = new Date();
var end = myDate.getSeconds();
if(parseInt(end) > time_array[0]){
var time = end - time_array[0];
alert("success! time:" + time);
return
}else{
var time = end - time_array[0]+60;
alert("success! time:" + time);
return
}
}
var lastElement = arrary[arrary.length-1];
if(num-1 != lastElement){
alert("失败!");
return
}
arrary.push(num);
}
}
</script>