使用jQuery写出猜数字游戏

 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>猜数字</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        h1{
            color: red;
        }
        p{
            color: blue;
        }
        #s{
            border: 1px solid black;
            width: 300px;
            height: 30px;
            display: inline-block;
            background-color: white;
            line-height: 30px;
        }
        #c{
            width: 50px;
        }
        #back{
            width: 800px;
            height: 534px;
            position: absolute;
        }
        #y{
            margin-left: 100px;
            margin-top: 20px;
            line-height: 50px;
        }
        video{
            position: fixed;
            right: 0;
            bottom: 0;
            min-width: 100%;
            min-height: 100%;
            height: 500px;
            width: 500px;
            z-index:-11
        }
    </style>
    <script src="../JS/jquery-1.12.4.js"></script>
</head>
<body>
    <div id="back">
        <video autoplay loop muted>
            <source src="../img/龙猫.mp4" type="video/mp4"  />
        </video>
        <div id="y">
            <h1>猜数字</h1>
            <p>这个数在100以内,你只有10次机会</p>
            <span id="s">请输入数字</span>
            猜吧:<input type="text" id="c">
            <button>确定</button>
        </div>
    </div>
</body>
<script>
    $(document).ready(function () {
        var number = Math.floor(Math.random()*100)+1;
        var s = "";
        $("button").click(function () {
            var text = Number($("#c").val());
            if (isNaN(text)){
                $("#s").html("你输入的不是数字")
            }else{
                if (text > 100 || text<1){
                    $("#s").html("输入数字不在范围内,请输入1-100以内")
                }else {
                    if (text < number){
                        s = String(text)+"这个数字太小了";
                        $("#s").html(s);
                    }else{
                        if (text > number){
                            s = String(text)+"这个数字太大了";
                            $("#s").html(s);
                        }
                        else{
                            s = String(text)+"恭喜你猜对了";
                            $("#s").html(s);
                        }
                    }
                }
            }
        })
    })
</script>
</html>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值