【发布时间】:2019-07-08 23:42:46
【问题描述】:
我正在尝试遍历一个无序列表并循环遍历每个列表项(使用 ticker-item 类)并临时附加一个类,以便 CSS 可以对其应用一些转换)。
var a = [];
$(".ticker-item").each(function(index) {
a[index] = $(this);
setTimeout(function() {
a[index].addClass('current').delay(500).queue(function(next) {
a[index].removeClass('current');
next();
});
}, index * 500);
});
我搜索了各种 SO 文章,我确信该函数将正确添加和删除类,但目前似乎没有应用 li 的?
这是 HTML:
<div class="ticker">
<ul class="ticker-items">
<li class="ticker-item">
<a href="/categories/featured/summer-sale/1185">
<p><strong>Summer Sale</strong>???? Now more things at <strong>50% off!</strong></p>
</a>
</li>
<li class="ticker-item">
<a href="/about">
<p>Things for kids you'll ???? too. <strong>Our story</strong></p>
</a>
</li>
<li class="ticker-item">
<a href="/help/delivery-and-returns">
<p><strong>Free</strong> Delivery* & <strong>Free</strong> Returns ????</p>
</a>
</li>
</ul>
</div>
【问题讨论】:
-
您缺少类选择器(一个点);
$("ticker-item")应该是$(".ticker-item") -
错字,
$('ticker-item')应该是$('.ticker-item')。投票结束是一个错字 -
抱歉,错字已修复,但问题依然存在。我需要添加一个 .也要当前?
标签: javascript jquery