Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/380.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用setTimeout延迟jQuery操作的计时_Javascript_Jquery - Fatal编程技术网

Javascript 使用setTimeout延迟jQuery操作的计时

Javascript 使用setTimeout延迟jQuery操作的计时,javascript,jquery,Javascript,Jquery,我试图延迟div中文本的交换。它应该像文本的滑块/旋转木马一样运行 我一定是把代码弄错了,因为最终的文本替换从未发生过 另外,我将如何设置引入替换文本(例如百叶窗)的动画 $(文档).ready(函数(){ $(“#showDiv”)。单击(函数(){ $('#theDiv')。show(1000,function(){ setTimeout(函数(){ $('#theDiv').html('这里是一些替换文本',function(){ setTimeout(函数(){ $('#theDiv

我试图延迟div中文本的交换。它应该像文本的滑块/旋转木马一样运行

我一定是把代码弄错了,因为最终的文本替换从未发生过

另外,我将如何设置引入替换文本(例如百叶窗)的动画



$(文档).ready(函数(){
$(“#showDiv”)。单击(函数(){
$('#theDiv')。show(1000,function(){
setTimeout(函数(){
$('#theDiv').html('这里是一些替换文本',function(){
setTimeout(函数(){
$('#theDiv').html('此处有更多替换文本');
}, 2500);
});
}, 2500);
});
});//单击函数结束
}); //END$(document.ready())
我下面是一个名为“theDiv”的DIV.

此文本位于名为“theDiv”的Div中。

.html()
只接受字符串或函数作为参数。试试这个:

 $("#showDiv").click(function () {
     $('#theDiv').show(1000, function () {
         setTimeout(function () {
             $('#theDiv').html(function () {
                 setTimeout(function () {
                     $('#theDiv').html('Here is some replacement text');
                 }, 0);
                 setTimeout(function () {
                     $('#theDiv').html('More replacement text goes here');
                 }, 2500);
             });
         }, 2500);
     });
 }); //click function ends

您也可以使用而不是
setTimeout()
。它将为您提供更可读的代码。以下是文档中的一个示例:

$( "#foo" ).slideUp( 300 ).delay( 800 ).fadeIn( 400 );
唯一的限制(我知道)是它没有给你一个清除超时的方法。如果您需要这样做,那么最好坚持使用
setTimeout
强加给您的所有嵌套回调。

尝试以下方法:

 $("#showDiv").click(function () {
     $('#theDiv').show(1000, function () {
         setTimeout(function () {
             $('#theDiv').html(function () {
                 setTimeout(function () {
                     $('#theDiv').html('Here is some replacement text');
                 }, 0);
                 setTimeout(function () {
                     $('#theDiv').html('More replacement text goes here');
                 }, 2500);
             });
         }, 2500);
     });
 }); //click function ends
function explode(){
  alert("Boom!");
}
setTimeout(explode, 2000);

这就是我解决问题的方法 鼠标退出几秒钟后菜单关闭(如果悬停没有启动)


如果我在那个房间里放一个。。脚本是否也将被刷新?事实上,你可以使用
clearQueue()
删除任何尚未执行的动画。最合适的工具应该是
.queue()
。。。
//Set timer switch
$setM_swith=0;

$(function(){
    $(".navbar-nav li a").click(function(event) {
        if (!$(this).parent().hasClass('dropdown'))
            $(".navbar-collapse").collapse('hide');
    });
    $(".navbar-collapse").mouseleave(function(){
        $setM_swith=1;
        setTimeout(function(){ 
           if($setM_swith==1) {
             $(".navbar-collapse").collapse('hide');
             $setM_swith=0;} 
        }, 3000);
    });
    $(".navbar-collapse").mouseover(function() {
        $setM_swith=0;
    });
 });