日期:2014-05-16  浏览次数:20375 次

Set timeout 使用 Jquery延迟执行 求助
<script type=text/javascript>
jQuery(function(){
jQuery('#webmenu li').hover(function(){
jQuery(this).children('ul').stop(true,true).show('normal');
},function(){
jQuery(this).children('ul').stop(true,true).hide('slow');
});
});
</script>

这是一段弹出菜单的代码,百度了一下说是用SET TIMEOUT的方法做延迟.可是搞了半天也没搞出来.麻烦各位帮忙改一下.谢谢了只是希望鼠标放上去的时候不是马上执行.而是延迟一下再执行.

------解决方案--------------------
JScript code
jQuery(function(){
    jQuery('#webmenu li').hover(
        function(){
            //鼠放悬浮其上时,延迟一秒显示
            var _that=jQuery(this);
            setTimeout(function(){
                _that.children('ul').stop(true,true).show('normal');
            },1000);
        },function(){
            //鼠放离开后,延迟一秒隐藏
            var _that=jQuery(this);
            setTimeout(function(){
                _that.children('ul').stop(true,true).hide('slow');
            },1000);
        }
    );
});