JavaScript怎么实现验证码倒计时插图

本文操作环境:windows7系统、javascript1.8.5版、Dell G3电脑。

JavaScript怎么实现验证码倒计时?

js获取验证码倒计时60s(超简单)

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>测试jquey的ajax方法</title>
    <style>
        *{
            padding:0;
            margin:0;
        }
        button{width: 20%;line-height: 50px;font-size: 30px;margin-left: 40%;margin-top: 20%;  }
    </style>
</head>
<body>
<div id="test"></div>
<button>获取验证码</button>
<script type="text/javascript" src="jquery-1.8.2.min.js"></script>
<script>
$('.hmac').on('click',function(){
   var that = $(this)
    var timeo = 60;
    var timeStop = setInterval(function(){
        timeo--;
        if (timeo>0) {
            that.text('重新发送' + timeo +'s');
            that.attr('disabled','disabled');//禁止点击
        }else{
            timeo = 60;//当减到0时赋值为60
            that.text('获取验证码'); 
            clearInterval(timeStop);//清除定时器
            that.removeAttr('disabled');//移除属性,可点击
        }
    },1000)
})
</script>
</body>
</html>

推荐学习:《javascript高级教程

以上就是JavaScript怎么实现验证码倒计时的详细内容,更多请关注亿码酷站其它相关文章!



JavaScript怎么实现验证码倒计时
—–文章转载自PHP中文网如有侵权请联系ymkuzhan@126.com删除

云服务器推荐