js延时防止鼠标误操作

 

var timer;
$("xxx").hover(
    function () {
        timer = setTimeout(code,3000);
    },
    function () {clearTimeout(timer)}
);

 

原理:setTimeout()计时执行一次,当鼠标移上去后开始计时,如果没有到设定时间,鼠标移出,则使用clearTimeout()清理掉计时器,这样就不会执行。

 

posted @ 2014-12-03 10:55  K13  阅读(335)  评论(0编辑  收藏  举报