1

当href包含某些文本时,我正在尝试打开页面上的所有链接,目前我正在使用

$('a[href*="/steve"]').each(function() {
  window.open($(this).attr('href') );   
});

现在我正在使用的页面在href中包含很多带有该文本的链接,因此它会在很短的时间内通过打开的窗口向我发送垃圾邮件,我想添加一个延迟,以便它有时间打开并等待大约5几秒钟前打开下一个。我试图使用 .delay 但无法让它工作,因为我很新并且不知道确切的位置。

4

2 回答 2

2

你可以这样做 :

$('a[href*="/steve"]').each(function(index) {
    setTimeout(
         function(href){window.open(href)},
         (index+1)*5000, $(this).attr('href')
    );
});

这个想法是setTimeout用不断增加的延迟来调用。

于 2012-12-02T15:04:42.830 回答
2

使用 setTimeout 添加延迟:

var i = 0;
$('a[href*="/steve"]').each(function() {
    ++i;
    setTimeout(function(href) { window.open(href) },i*5000, $(this).attr("href"));
});
于 2012-12-02T15:04:49.910 回答