$(function(){
window.location.href = $('.links').attr('href');
});
班级名称是"链接"它下面有很多链接,我如何为每个链接点击添加一个延迟,而不是让脚本一次又一次地点击同一个链接?
由于
答案 0 :(得分:0)
$(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();
});
});