美文网首页
按钮禁用

按钮禁用

作者: 前端技师胡帅博 | 来源:发表于2020-09-10 14:44 被阅读0次
    // 恢复初始状态
        const init = (countTime) => {
          window.holdTime = 3;
          window.btn = e('#btn');
          $(btn).removeAttr('disabled');
          btn.innerText = '可以点击';
          clearInterval(countTime);
        };
    
        // 读秒计时间
        const counting = () => {
          let countTime = setInterval(() => {
            holdTime--;
            btn.innerText = holdTime + '秒后才能再次点击';
            if (holdTime == 0) {
              init(countTime);
            }
          }, 1000);
        };
    
        const __main = () => {
          init();
          bindEvent(btn, 'click', (e) => {
            btn.innerText = holdTime + '秒后才能再次点击';
            $(btn).attr('disabled', true);
            counting();
          });
        };
    
        __main();
    

    相关文章

      网友评论

          本文标题:按钮禁用

          本文链接:https://www.haomeiwen.com/subject/pkxbektx.html