gpt4 book ai didi

javascript - 我使用 eq(...) 不正确吗?或者这里有什么问题?

转载 作者:搜寻专家 更新时间:2023-10-31 22:59:52 25 4
gpt4 key购买 nike

我有一个 HTML block

<tbody>
<tr id="first-score-row">
<td>Steve Ballmer</td>
<td>1923</td>
<td class="hide-under-480px">10/11/2015 9:21:39 PM</td>
</tr>
<tr>
<td colspan="3">
<p><a class="btn btn-primary btn-lg show-fewer-or-more-scores" id="show-more-scores">Click to See More</a></p>
</td>
</tr>
<tr class="hidden">
<td>Michael Jackson</td>
<td>300</td>
<td class="hide-under-480px">10/6/2015 2:37:30 PM</td>
</tr>
<tr class="hidden">
<td>Weird Al</td>
<td>180</td>
<td class="hide-under-480px">10/10/2015 1:20:38 AM</td>
</tr>
<tr class="hidden">
<td>Obama smokes cigs</td>
<td>60</td>
<td class="hide-under-480px">10/5/2015 10:28:37 PM</td>
</tr>
<tr class="hidden">
<td>Donald Trump</td>
<td>60</td>
<td class="hide-under-480px">10/5/2015 10:28:02 PM</td>
</tr>
<tr class="hidden">
<td colspan="3">
<div class="row">
<div class="col-xs-12 col-sm-6 col-md-6 col-lg-6">
<p><a class="btn btn-primary btn-lg show-fewer-or-more-scores" id="show-fewer-scores" target="_blank">See Fewer Scores</a></p>
</div>
<div class="col-xs-12 col-sm-6 col-md-6 col-lg-6">
<p><a href="/Scores" class="btn btn-primary btn-lg" target="_blank">See <u>All</u> Scores</a></p>
</div>
</div>
</td>
</tr>
</tbody>

我正在尝试制作一个事件,以动画方式显示或隐藏除第一行(将始终显示)之外的所有行,每行之间间隔 1/5 秒。我尝试的事件处理程序是

// click function for the "See More Scores" and "See Fewer Scores" buttons
$('.show-fewer-or-more-scores').click(function ( )
{
var otherRows = $(this).closest('tbody').children('tr:not(#first-score-row)');
for (var k = 0, n = otherRows.length; k < n; ++k)
{
setTimeout(function () {
otherRows.eq(k).toggleClass('hidden');
}, k * 200 );
}

});

出于某种原因,它无法正常工作。没有错误打印到控制台,但没有任何反应,类 hidden 没有切换。我在这里做错了什么?

实例here

最佳答案

要定位除第一行以外的所有行,请使用:gt(0) 选择器:

jsBin demo

var $rowsNotFirst = $("table tbody tr:gt(0)");
var $scoresBtn = $(".show-fewer-or-more-scores");


$scoresBtn.click(function(){
$rowsNotFirst.toggleClass("hidden");
});

添加超时:

jsbin demo

$scoresBtn.click(function(){
$rowsNotFirst.filter(function(idx, el){
setTimeout(function(){
$(el).toggleClass("hidden");
}, 300*idx); // 300 * element index
});
});

关于javascript - 我使用 eq(...) 不正确吗?或者这里有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33073468/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com