猜数小游戏

来源:互联网 发布:讲政治知敬畏守规矩 编辑:程序博客网 时间:2024/06/11 23:27

猜数小游戏截图]

<!DOCTYPE html><html>    <head>        <meta charset="UTF-8">        <title></title>        <script type="text/javascript" src="js/jquery-3.2.1.min.js"></script>        <style type="text/css">            h2 {                margin: 0 auto;            }            #sp1 {                background-color: #F5F5F5;                border-radius: 5px;                padding: 16px;                font-size: 14px;                font-weight: 700;                width: 300px;                display: inline-block;            }            #yan {                background-color: #337AB7;                color: white;                border-radius: 5px;                border: none;                padding: 3px 10px;            }            #again {                background-color: #5CB85C;                color: white;                border-radius: 5px;                border: none;                padding: 3px 10px;            }            #sp3 {                background-color: #777777;                color: white;                border-radius: 15px;                border: none;                padding: 3px 9px;                display: none;            }        </style>    </head>    <body>        <h2>猜数游戏</h2>        <span id="sp1">猜一猜,多大值?(1-1000)</span><br /><br /> 我猜是:        <input type="text" id="n" />        <input type="button" id="yan" value="验证" onclick="randomnum()" />        <input type="button" id="again" value="再玩一次" onclick="againgo()" /><br />        <span id="sp2"></span><br /> 猜测次数:        <span id="sp3"></span>        <script>            var num = parseInt(Math.random(1000) * 1000 + 1);            console.log(num);            var i = 0;            function randomnum() {                i++;                $("#sp3").show();                $("#sp3").html(i);                if($("#n").val() == num) {                    $("#yan").attr("disabled", false);                    $("#sp2").html("回答正确");                    i = 0;                } else if($("#n").val() > num) {                    $("#sp2").html("有点大了,小点试试");                } else if($("#n").val() < num) {                    $("#sp2").html("有点小了,大点试试");                }            }            function againgo() {                num = parseInt(Math.random(1000) * 1000 + 1);                $("#sp2").html("");                i = 0;                $("#sp3").hide();                $("#n").val("")                console.log(num);            }        </script>    </body></html>
原创粉丝点击