如何告诉Jquery命令行在每个命令行之后添加延迟

如何告诉Jquery命令行在每个命令行之后添加延迟,jquery,delay,wait,Jquery,Delay,Wait,我所拥有的: $(document).ready(function(e){ // NL flag $(this).find("#topbar_nl").width('100%'); $(this).find("#midbar_nl").width('100%'); $(this).find("#botbar_nl").width('100%'); }); 我需要它来做这样的事情: $(document).ready(function(e)

我所拥有的:

$(document).ready(function(e){
                // NL flag
    $(this).find("#topbar_nl").width('100%');
    $(this).find("#midbar_nl").width('100%');
    $(this).find("#botbar_nl").width('100%');
});
我需要它来做这样的事情:

$(document).ready(function(e){
                // NL flag
    $(this).find("#topbar_nl").width('100%');(wait for 2 seconds then go to next command line)
    $(this).find("#midbar_nl").width('100%');(wait for 2 seconds then go to next command line)
    $(this).find("#botbar_nl").width('100%');(wait for 2 seconds then go to next command line)
});
好吧,你可以做到

var arr =["#topbar_nl", "#midbar_nl", "#botbar_nl"], index = 0;
setInterval(function(){ // use setInterval for the delay
   if(index < arr.length) {
      $(this).find(arr[count]).width('100%'); // do the work
   }  index++; // update the index
}, 2000) // of 2 seconds
var arr=[“#topbar_nl”、“#midbar_nl”、“#botbar_nl”],索引=0;
setInterval(函数(){//延迟使用setInterval
if(索引
您可以使用此方法:

$(this).find("#topbar_nl").animate( { width: '100%' }, 2000, function() {
    $(this).find("#midbar_nl").animate( { width: '100%' }, 2000, function() {
        $(this).find("#botbar_nl").animate( { width: '100%' }, 2000 );
    });
});

虽然这可以工作,但它会使
宽度
动画持续2秒,这可能不是OP想要的。难道没有更简单的方法来添加延迟吗?我知道,只要在一个命令行中有多个操作,.delay()就可以工作。难道没有一种方法可以做到这一点,或者需要更少的代码吗?