Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/fsharp/3.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中已计时的函数内设置超时_Javascript_Settimeout - Fatal编程技术网

如何在javascript中已计时的函数内设置超时

如何在javascript中已计时的函数内设置超时,javascript,settimeout,Javascript,Settimeout,我正在努力展示一个本质上是自我贬低的信息。5秒后,消息栏自动关闭。但是,当显示多条消息时,一旦显示的消息栏被取消,行为是在同一容器中显示多条消息 为此,, 当我显示第一条信息时,下面是5秒后自动关闭的代码 window.setTimeout(function () { bar.getValue('isVisible').setValue(false); this.clearMessage(bar);// clears the message bar._isShow

我正在努力展示一个本质上是自我贬低的信息。5秒后,消息栏自动关闭。但是,当显示多条消息时,一旦显示的消息栏被取消,行为是在同一容器中显示多条消息

为此,, 当我显示第一条信息时,下面是5秒后自动关闭的代码

    window.setTimeout(function () {
    bar.getValue('isVisible').setValue(false);
    this.clearMessage(bar);// clears the message
    bar._isShowing = false;
        setTimeout(function() {
            //execute the last action in the queue (if any)
            dequeueAction(); fires the next message in queue.
        }, 100);
     }, 3000);
我的问题是,当有另一条消息在第一条消息自行消失之前被触发时,我正在排队等待它。但是,我希望在取消第一条消息和在队列中显示第二条消息之间有相当大的延迟。但是显示第二条消息的超时延迟不起作用,因为它已经在3000毫秒的时间内

我怎样才能延迟解除第一条消息并显示第二条消息? 注意:它在没有第二次设置超时的情况下工作,但没有延迟


任何帮助都将不胜感激。

我不能100%肯定我理解你的问题。我想你说的是你想:

  • 显示自动关闭的消息
  • 如果消息在显示时到达,它将排队
  • 一旦当前消息self dismissed,在显示下一条消息之前应该有一个短暂的暂停
  • 牢记这些目标:

    //message queue
    var msgqueue = Array();
    //displaying flag
    var msgdisplaying = null;
    
    //clear message and hide box/bar
    function clearMessage() {
        msgdisplaying = null;
        $('#msgbox').css('display','none');
    }   
    
    //queue message, start display if no message showing
    function displayMessage(msg) {
        msgqueue.push(msg);
        if (msgdisplaying === null) showMessage();
    }
    
    //display message and set dismiss/delay timers
    function showMessage() {
        if (msgqueue.length > 0) {
            $("#msgbox").html("<h1>" + msgqueue.shift() + "</h1>").css('display','block');
            //dismiss this message after 3 seconds
            setTimeout("clearMessage();",3000);
            //display next message (if any) 0.1 seconds after dismissing
            msgdisplaying = setTimeout("showMessage();", 3100);
        }          
    }
    

    这不是3000秒,而是3000毫秒,也就是3秒。是的,我理解。这是一个输入错误。不用担心,只是检查一下。我不理解确切的问题-它应该可以像这样工作,因为您可以在Javascript中使用嵌套函数。你能描述一下它现在不工作的方式吗?听起来像是
    bar.\u isShowing=false位于错误的位置。你能告诉我们整个功能吗?
    
    //show
    $("#msgbox").html("<h1>" + msgqueue.shift() + "</h1>")
    $("#msgbox").animate({ 'opacity': 1 }, 500, 'swing', function() { 
       msgdisplaying = setTimeout("dismissMessage();", 3000) 
     });
    
    //hide
    $("#msgbox").animate({ 'opacity': 0 }, 500, 'swing', function(){ 
       if (msgqueue.length > 0) 
          msgdisplaying = setTimeout("showMessage();", 1000) 
       } else { 
          msgdisplaying = null 
       });