1、添加flag
适用于ajax 表单提交,提交之前flag = false , 提及中,true ,提交后false
2、事件重复点击:
<script> var throttle = function (fn, delay) { var timer = null; return function () { var args = arguments; //参数集合 console.log("arguments",arguments); console.log("timer",timer); clearTimeout(timer);//重复执行的都clear掉了 timer = setTimeout(function () { fn.apply(this, args); }, delay); } } /** * 要执行的方法 * @param String name 传递的参数 */ function postFun(name) { document.writeln("name:" + name); } //================测试部分 => 【1s重复点击10次】 var t = throttle(postFun, 100); var ejector = setInterval(() => { t("333"); }, 100); // 10 ci setTimeout(() => { clearInterval(ejector); }, 1000); </script>