<html>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<script>

 function makenum(){

    var a1=document.getElementById("a");

 var t=parseInt(Math.random()*8 + 1);

 a1.value=t;

 initCount();
var start=Date;

 alert(start);

 }

 function initCount(){

   count=0;

 }


 
 function check(){

   var num=document.getElementById("a").value;

   var num1=document.getElementById("c").value;

   var check="0123456789";

   for(var i=0;i<num1.length;i++){

     var ran=num1.charAt(i);

  if(check.lastIndexOf(ran)<0){

      alert('请输入数字');

   return false;

  }

   }

   if(num1>num){

      alert('你猜的大了');

   count++;

   }else if(num1<num){

      alert('你猜的小了');

   count++;

   }else if(num1==num){

     count++;

     alert('你猜了'+count+'次,终于猜对了');

  initCount();

   }

 }

</script>

<body>

<input type="password" />

<input type="button" value="生成随机数字"  onclick="makenum()"/><br>

<input type="text" />

<input type="button" " value="看看对了没有" onclick="check()"/>

</body>

</html>

相关文章:

  • 2021-04-17
  • 2021-08-03
  • 2021-11-14
  • 2021-07-30
  • 2021-04-16
  • 2021-10-18
  • 2021-11-30
  • 2021-11-30
猜你喜欢
  • 2019-01-09
  • 2019-12-28
  • 2021-04-18
  • 2021-11-30
  • 2021-08-23
相关资源
相似解决方案