Wait/Pause/Sleep in jQuery Each Loop between Iterations
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I simply want to add a pause after each iteration of a jQuery each loop, I can't seem to figure it out. $(".item").each(function(i){ var el = this; var timer = setTimeout(function(){ $(el).trigger("click"); }, 500); }); This is not firing every 1/2 second, but rather triggering click on all items at once. I want something like this (pseudocode): $(".item").each(function(i){ $(this).trigger("click"); wait(500); // wait a half second before the next iteration }); Any working method of this? 回答1: You cannot really do this with $.each . You can