首页 > 其他 > 详细

提交安钮 提交一次加了 59秒倒计时

时间:2015-07-02 19:07:53      阅读:98      评论:0      收藏:0      [点我收藏+]

实现点击“发送验证码”按钮后,按钮依次显示为“59秒后重试”、“58秒后重试”…直至倒计时至0秒时再恢复显示为“发送验证码”。在倒计时期间按钮为禁用状态

技术分享

 PS:  当倒计时开始的时候。 要把 计时器 清了。 不要然会点击, 加快秒数。

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <script type="text/javascript">
        window.onload = function () {
            var send = document.getElementById(send),
                times = 60,
                timer = null;
            send.onclick = function () {
                // 计时开始
                timer = setInterval(function () {
                    times--;
                    if (times <= 0) {
                        send.value = 发送验证码;
                        clearInterval(timer);
                        send.disabled = false;
                    } else {
                        send.value = times + 秒后重试
                        send.disabled = true;
                    }
                    console.log(times)
                }, 1000)

            }
        }
    </script>
</head>
<body>
<input type="button" id="send" value="发送验证码">
</body>
</html>

 

提交安钮 提交一次加了 59秒倒计时

原文:http://www.cnblogs.com/yjhua/p/4616682.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!