比如mouseenter事件 怎样才能防止被频繁触发 只让他一秒内只被触发一次 ?
求助

解决方案 »

  1.   

    如果是用jquery,可以 delay 加 stop如果自己写,那么可以设置标志,第一次触发之后设为false,一段时间后再改为true,此期间再触发事件时直接 return
      

  2.   

    设置一个公共变量__interval,当mouseEnter事件时,
    if(__interval==null){
      __interval=window.setInterval("yourFunction()",1000);
    }
      

  3.   

    <HTML>
    <HEAD>
    <TITLE> New Document </TITLE>
    <script type="text/javascript">
    window.onload = function() {
    var couldRun = true; document.getElementById('d').onmouseenter = function(){
    if(couldRun) {
    couldRun = false;
    // 这里放你需要的方法
    // ...
    // 一秒后将变为可运行
    setTimeout(function(){
    couldRun = true;
    },1000);
    }
    }
    }
    </script>
    </HEAD><BODY>
    <div id="d" style="width:100px;height:100px;background-color:#ccc"><div>
    </BODY>
    </HTML>