熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> JSP教程 >> 正文

猜數

2022-06-13   來源: JSP教程 

  腳本說明:
第一步:把如下代碼加入<head>區域中
<SCRIPT LANGUAGE=JavaScript>
var js_mult=
var js_mult=
var js_m=
var js_m=
var js_iseed=
var js_iseed=
var js_iseed=
function random(n)
{
    if (js_iseed == )
    {
        now = new Date()
        js_iseed = nowgetHours() + nowgetMinutes() *
                    + nowgetSeconds() *
    }
    js_iseed = js_iseed / js_m
    js_iseed = js_iseed % js_m
    var tmp = (((js_iseed * js_mult + js_iseed * js_mult) % js_m) *
                js_m + (js_iseed * js_mult)) % js_m
    js_iseed = (tmp + ) % js_m
    return (Mathfloor((js_iseed/js_m) * n))
}
var myNumber =
var nGuesses =
function guessnum()
{
   var response
    var num = parseInt(documentforms[]guessvalue)
    documentforms[]guessvalue = num // visual feedback in case of NaN
    nGuesses++ // increase the guess count
    response = 你猜的數
    if (num < myNumber)    response = response + 太小了
    if (num > myNumber)    response = response + 太大了
    if (num == myNumber)
    {
        response = response + 對了!!你猜到我了!
        nGuesses =
        myNumber = random()+
    }
    documentforms[]resultvalue=response
    documentforms[]guessesvalue=nGuesses
    documentforms[]guessfocus()
    documentforms[]guessselect()
    return true
}
function giveup()
{
    var response
    nGuesses =
    response = 我的數字是 + myNumber +  想猜我的新數嗎?
    myNumber = random()+
    documentforms[]resultvalue=response
    documentforms[]guessesvalue=nGuesses
    documentforms[]guessfocus()
    documentforms[]guessselect()
}
</SCRIPT>

  <font size= color=#FF>
我手中有一個數它的范圍在~之間你能猜到它是幾嗎?</font></b><font size=>
</font>
<SCRIPT>
    myNumber = random()+
    nGuesses =
</SCRIPT>
<FORM onSubmit=guessnum(); return false>
填入你猜的數: <INPUT TYPE=text NAME=guess SIZE=
<INPUT TYPE=button VALUE=     我來猜   onClick=guessnum()
<INPUT TYPE=button VALUE=  放棄  onClick=giveup()
</FORM> 
<FORM>
你已猜了: <INPUT TYPE=text NAME=guesses SIZE=>次
提示信息: <INPUT TYPE=text NAME=result SIZE=>
</FORM> 

  第二步:把<body>區域中的內容改為:
<body bgcolor=#fefd onLoad=documentforms[]guessfocus(); documentforms[]guessselect()>


From:http://tw.wingwit.com/Article/program/Java/JSP/201311/19173.html
  • 上一篇文章:

  • 下一篇文章:
  • 推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.