使用Javascript单击同一类中的多个链接,但在单击的每个不同链接之间存在延迟
类名是links,它下面有很多链接,如何为每个链接单击添加延迟,而不是让脚本一次又一次地单击同一链接 谢谢使用Javascript单击同一类中的多个链接,但在单击的每个不同链接之间存在延迟,javascript,jquery,Javascript,Jquery,类名是links,它下面有很多链接,如何为每个链接单击添加延迟,而不是让脚本一次又一次地单击同一链接 谢谢 $(function(){ window.location.href = $('.links').attr('href'); }); $(function () { // Grab all links into a wrapped set. var $links = $('.link'); // Start with the first link at index 0
$(function(){
window.location.href = $('.links').attr('href');
});
$(function () {
// Grab all links into a wrapped set.
var $links = $('.link');
// Start with the first link at index 0 in the wrapped set.
var linkNum = 0;
// Specify our delay time.
var delay = 1; // seconds
// Setup a click handler on all our links.
$links.click(function (e) {
var $this = $(this);
console.log($this.text() + ' clicked.');
$this.css({ color: '#f00' });
// After our delay, click the next link.
setTimeout(function () {
++linkNum;
if (linkNum < $links.length) {
$links.eq(linkNum).click();
} else {
linkNum = 0;
console.log("All links clicked.");
}
}, delay * 1000);
});
$('button').click(function () {
$links.eq(0).click();
});
});