获取验证码

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>获取验证码</title>
    <script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
</head>
<body>
    <input type="button" id = "btn" value="获取验证码">
</body>
<script>
    // setinterval()  方法可按照指定的周期(以毫秒)来调用函数或计算表达式
    // setInterval()  方法会不停的调用函数,直到 clearInterval() 被调用或窗口被关闭
    $(function(){
        $("#btn").click(function(){
            var count = 10;
            var countdown = setInterval(CountDown,1000);
            function CountDown(){
                $("#btn").attr("disabled",true);
                $("#btn").val(count + "秒后重新发送!");
               if(count==0)
               {
                $("#btn").val("获取验证吗").removeAttr("disabled");
                clearInterval(countdown);
                alert('你好');
               }
               count--;
            }
           
        })
    })
</script>
</html>

你可能感兴趣的:(获取验证码)