js 按钮连击 减少触发事件次数

<body>
<input type="button" onClick="testbtn()" value="测试按钮">
<script>
  var b1 = true;
  function testbtn() {
      if (b1 == true) {
          b1 = false;
          setTimeout(function(){
            b1 = true;
          }, 1500);
          console.log(b1);
          console.log("0000");
      }
  }
    </script>
</body>

 

  var test = false;
    layui.use(['form'

 if (test == false) {
                test = !test;
    if (result.success) {
                        layer.msg(result.msg);
                        setTimeout(function () {
                            test = !test;
                            window.location.href = "xxx";
                        }, 1000);
                    }

 

      if (b_3) {
                    b_3 = !1;
                    setTimeout(function () {
                        d3_click(); //事件中还原b_3的值
                    }, "100");  //2000毫秒后执行test()函数,只执行一次。
                }

 

      var isclick = true;
        function post_test() {
            if (isclick) {
                isclick = false;
                //---
//---
                setTimeout(function () {
                    isclick = true;
                }, 500);
            }
        }

 

posted @ 2018-06-25 11:59  enych  阅读(330)  评论(0编辑  收藏  举报