⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch13_6.htm

📁 名字是《JavaScript从入门到精通》。但是其实是JavaScript的一些比较简单实用的例子
💻 HTM
字号:
 <!--======================================-->
 <!--  范例程序 CH13_6.HTML                 -->
 <!--======================================-->
 <HTML>
 <HEAD>
 <TITLE>赛马游戏</TITLE>
 <Script Language="JavaScript">
 
   var money=1000
   var steps=new Array(""," ","  ","   ",
                       "    ","     ")
   var fast=0
   var ID
   
   function getyou()
   {
   tmp=parseInt(document.ThisForm.money.value)
     if(money!=tmp)
     {
       alert("请勿自行更改金额!")
       document.ThisForm.money.value=money
     }
   }
   
   function Start()
   {
     var judge=0
     if(document.ThisForm.bet.value=="" ||
        document.ThisForm.bet.value<=0)
     {
       alert("请输入您的金额!")
       document.ThisForm.bet.value=""
     }
     else
     {
       if(document.ThisForm.bet.value>money)
       {
         alert("您输入的分数大于您的金额,请重新输入!")
         document.ThisForm.bet.value=""
       }
       else
       {
         gorun()
       }
     }
   }
   
   function gorun()
   {  
     tmp=parseInt(Math.random()*5)+1
     document.ThisForm.h1.value=steps[tmp]+
     document.ThisForm.h1.value
     tmp=parseInt(Math.random()*5)+1
     document.ThisForm.h2.value=steps[tmp]+
     document.ThisForm.h2.value
     tmp=parseInt(Math.random()*5)+1
     document.ThisForm.h3.value=steps[tmp]+
     document.ThisForm.h3.value
     tmp=parseInt(Math.random()*5)+1
     document.ThisForm.h4.value=steps[tmp]+
     document.ThisForm.h4.value
     tmp=parseInt(Math.random()*5)+1
     document.ThisForm.h5.value=steps[tmp]+
     document.ThisForm.h5.value
     tmp=parseInt(Math.random()*5)+1
     document.ThisForm.h6.value=steps[tmp]+
     document.ThisForm.h6.value
     ID=setTimeout("gorun()",10)
     winner()
     if(fast!=0)
     {
     clearTimeout(ID)
     alert(fast+"号获胜!!")
     if(fast==document.ThisForm.which.value)
     {
     alert("恭喜您猜中奖了!")
     money=money+document.ThisForm.bet.value*6
     document.ThisForm.reset()
     document.ThisForm.money.value=money
     fast=0
     }
     else
     {
     alert("很可惜!没有猜中,再来一次吧!")
     money=money-document.ThisForm.bet.value
     document.ThisForm.reset()
     document.ThisForm.money.value=money
     fast=0
     }
     }
   }
   
   function winner()
   {
     s1=document.ThisForm.h1.value
     s2=document.ThisForm.h2.value
     s3=document.ThisForm.h3.value
     s4=document.ThisForm.h4.value
     s5=document.ThisForm.h5.value
     s6=document.ThisForm.h6.value
     if(s1.length>=160) fast=1
     if(s2.length>=160) fast=2
     if(s3.length>=160) fast=3
     if(s4.length>=160) fast=4
     if(s5.length>=160) fast=5
     if(s6.length>=160) fast=6
   }
   
 </Script>  
 </HEAD>
 
 <BODY BackGround="bg.jpg">
 <Center><Font Color=Red Size=4>
 赛马游戏
 </Font></Center>
 
 <FORM Name="ThisForm">
 <INPUT TYPE=Text Name="h1" Size=70
  Value="1"><BR>
 <INPUT TYPE=Text Name="h2" Size=70
  Value="2"><BR>
 <INPUT TYPE=Text Name="h3" Size=70
  Value="3"><BR>
 <INPUT TYPE=Text Name="h4" Size=70
  Value="4"><BR>
 <INPUT TYPE=Text Name="h5" Size=70
  Value="5"><BR>
 <INPUT TYPE=Text Name="h6" Size=70
  Value="6"><BR>
 <HR>
 奖金总数:<INPUT TYPE=Text Name="money" 
 Value="1000" Size=10 OnChange="getyou()">元
 <BR>
 奖励金额:<INPUT TYPE=Text Name="bet"
 Size=10>元<BR>
 竟猜编号:<SELECT Name="which">
 <OPTION Value="1">1号
 <OPTION Value="2">2号
 <OPTION Value="3">3号
 <OPTION Value="4">4号
 <OPTION Value="5">5号
 <OPTION Value="6">6号</SELECT><BR><BR>
 <INPUT Type=Button Name="Press" Value="开始"
  OnClick="Start()">
 
 </BODY>
 </HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -