- var num = parseInt(Math.random()*100);
-
- document.getElementById("divid1").innerText = num;
- var nums = parseInt(0);
-
- function guess()
- {
- nums = ++nums;
- var younum = parseInt(document.getElementById("tex").value);
- if(isNaN(younum))
- {
- document.getElementById("divid1").innerText = "你没有输入任何数字,你已经猜了"+nums+"次";
- }
- else if(younum == num)
- {
- document.getElementById("divid1").innerText = "你第"+nums+"次的数字是"+younum+",恭喜你猜中了!";
- }
- else if(younum>num){
- document.getElementById("divid1").innerText = "你第"+nums+"次猜的数字是"+younum+",太大了!";
- }
- else{
- document.getElementById("divid1").innerText = "你第"+nums+"次猜的数字是"+younum+",太小了!";
- }
- document.getElementById("tex").value = "";
- document.getElementById("tex").focus();
- }
复制代码
|