【发布时间】:2014-07-18 03:08:19
【问题描述】:
我想替换$('#divy a:lt(3)')并添加变量而不是数字$('#divy a:lt(count)'),但它不起作用。
var timerId,
count = 0;
function end_counter() {
$('#divy a:lt(3)').each(function () {
var $this = $(this);
$this.attr('target', '_blank');
$this.get(0).click(function () {
window.open(this);
return false;
});
});
count = 0;
}
$('button').click(function () {
count++;
clearTimeout(timerId);
timerId = setTimeout(end_counter, 700);
});
【问题讨论】:
-
您的总体目标是什么?你到底想用这段代码完成什么?告诉我们您要替换
$('#divy a:lt(3)')并没有帮助,因为我们不知道您的最终目标。 -
get(0)返回一个DOM对象,而不是jQuery对象,而且因为$this是.each的主题,所以没有理由使用get,因为@无论如何,987654332@ 只是一个元素。 -
当 3 存在时,它将打开 div 中的前 3 个 href,方法是添加一个变量名而不是我想要更改打开的 href 数量的数字,例如:count = 5,打开前5页。但是当添加变量名而不是数字时它不起作用。
标签: javascript jquery