zoukankan      html  css  js  c++  java
  • 发送验证码倒计时案例

     
     
    <!DOCTYPE html>
    <html lang="en">

    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Document</title>
    </head>

    <body>
        手机号: <input type="number">
        <button>发送</button>

        <script>
            var btn = document.querySelector('button');
            var time = 60; // 剩下的秒数 
            btn.addEventListener('click', function() {
                this.disabled = true;
                var timer = setInterval(() => {
                    if (time == 0) {
                        // 清除定时器和复原按钮
                        clearInterval(timer);
                        btn.disabled = false;
                        btn.innerHTML = '发送';
                        time = 60; // 需要重新开始计算时间
                    } else {
                        btn.innerHTML = '还剩' + time + '秒..';
                        time--;
                    }
                }, 1000);

            })
        </script>
    </body>

    </html>
  • 相关阅读:
    第二章
    第一章
    unity--实现新手引导功能
    golang MissingContentLength error
    遇到一个golang time.Tick的坑
    grpc client连接池及负载均衡实现
    Pytorch学习-线性回归
    Pytorch学习-自动求导
    Pytorch学习-线性代数实现
    天池Python训练营笔记—Python基础进阶:从函数到高级魔法方法
  • 原文地址:https://www.cnblogs.com/ericblog1992/p/13055952.html
Copyright © 2011-2022 走看看