zoukankan      html  css  js  c++  java
  • 发送短信按钮倒计时案例

    <body>
        <input type="text">
        <button>发送</button>
    </body>
    <script>
        var sent = document.querySelector('button');
        var search = document.querySelector('input');
        var time = 10;  //10秒倒计时
        sent.addEventListener('click', function () {
            sent.disabled = true;   //禁用按钮
            sent.innerHTML = '还剩' + time + '';  //消去一秒空白
            var timer = setInterval(function () {//每秒执行
                if (time === 1) {    //停止重复
                    sent.innerHTML = '发送';  //恢复初始按钮状态
                    sent.disabled = false;  //取消按钮禁用
                    time = 10;  //回复秒数,供下次使用
                    clearInterval(timer);  //停止计时
                } else {
                    time--;  //秒数递减
                    sent.innerHTML = '还剩' + time + ''; //显示秒数
                }
            }, 1000);
        });
    </script>
  • 相关阅读:
    Graphic
    GUI编程实战
    Swing 混合布局
    运算符与数据库函数
    mysq基础操作
    mysql常见问题处理
    static 与final abstract关键字
    JAVA面试
    Swing
    AWT的应用
  • 原文地址:https://www.cnblogs.com/WP-WangPin/p/13796617.html
Copyright © 2011-2022 走看看