Document
猜字游戏
var txt=document.getElementById("txt");
var p=document.getElementById("p");
var angen=document.getElementById("angen");
var n=parseInt(Math.random()*10)+1;
var m=1;
angen.οnclick=function(){
txt.value="";
m=1;
n=parseInt(Math.random()*10)+1;
}
p.οnclick=function(){
if(txt.value=="")
{alert("null");
return;
}
if(isNaN(txt.value) || txt.value.length>2){
alert("请输入1-2位数字");
return;
}
var t=parseInt(txt.value);
if(m<=3){
if(t
{alert("小了");}
else if(t>n)
{alert("大了");}
else
{alert("正确");
return;
}
}
m++;
if(m>3)
{alert("次数完");}
else
{alert("还剩"+(4-m)+"次了");}
}
本文来源于网络:查看 >https://www.cnblogs.com/mrluobiao/p/6736426.html