Jquery toggle()仅需要表行
我有一个从php循环生成的表,所以切换的行具有相同的类。当我单击切换以显示一条记录的详细信息时,它切换到所有其他记录 这有点令人困惑。所以我试着在这里创建一个Jquery toggle()仅需要表行,jquery,Jquery,我有一个从php循环生成的表,所以切换的行具有相同的类。当我单击切换以显示一条记录的详细信息时,它切换到所有其他记录 这有点令人困惑。所以我试着在这里创建一个 A先生 记录1。。。。 记录2。。。。 B先生 记录1。。。。 $(文档).ready(函数(){ $(“.details”).hide(); $(“.showit”)。单击(函数(){ $(“.details”).toggle(); }); }); 问题是,当我点击显示A先生的记录时,它也会显示B先生的记录。有什么解决方案吗?非常感
A先生
记录1。。。。
记录2。。。。
B先生
记录1。。。。
$(文档).ready(函数(){
$(“.details”).hide();
$(“.showit”)。单击(函数(){
$(“.details”).toggle();
});
});
问题是,当我点击显示A先生的记录时,它也会显示B先生的记录。有什么解决方案吗?非常感谢…您可以捕获单击的行,并检索包含类详细信息的所有后续行:
$(".showit").click(function(){
$(this).closest("tr") // Retrieves the tr that was clicked
.nextUntil(":not(.details)") // Gets all the following tr's that have the detail class
.toggle();
});
更新的fiddle:非常流畅-直到现在才听说nextUntil()。干得好,也没有想过使用
nextUntil()
。嗯,我想
$(".showit").click(function(){
$(this).closest("tr") // Retrieves the tr that was clicked
.nextUntil(":not(.details)") // Gets all the following tr's that have the detail class
.toggle();
});