以文本方式查看主题

-  课外天地 李树青  (http://www.njcie.com/bbs/index.asp)
--  Web技术  (http://www.njcie.com/bbs/list.asp?boardid=28)
----  课上练习代码——猜数字  (http://www.njcie.com/bbs/dispbbs.asp?boardid=28&id=1513)

--  作者:admin
--  发布时间:2015/5/26 12:09:04
--  课上练习代码——猜数字

<pre>

 

<!DOCTYPE html>

<html>

<head lang="en">

    <meta charset="UTF-8">

    <title></title>

    <script language="JavaScript">

        var hiddenRandom;

        function func2() {

            hiddenRandom = Math.ceil(Math.random() * 100);

            document.getElementById("oneRandom").value = hiddenRandom;

        }

        function func1() {

            var oneRandom = document.getElementById("oneRandom").value;

            if (hiddenRandom > oneRandom) {

                alert("太小了");

            }

            else if (hiddenRandom < oneRandom) {

                alert("太大了");

            }

            else {

                alert("猜中了");

            }

        }

    </script>

</head>

<body onload="func2()">

<form name="myFrm">

    你猜一个数字(1-100):

    <input type="text" id="oneRandom" size="12"/>

    <br/>

    <input type="button" value="计算" onclick="func1()"/>

</form>

</body>

</html>

 

</pre>

[此贴子已经被作者于2015-05-26 12:12:26编辑过]