gpt4 book ai didi

javascript - 使用 jQuery,如何找到出现在另一个类之间的类的所有实例

转载 作者:行者123 更新时间:2023-11-30 07:48:09 25 4
gpt4 key购买 nike

例如:

<table>
<tr class="highlight" id="click">
<td>Rusty</td>
</tr>
<tr class="indent">
<td>Dean</td>
</tr>
<tr class="indent">
<td>Hank</td>
</tr>
<tr class="highlight">
<td>Myra</td>
</tr>
</table>

比如说,当我点击 id 为 click 的 hr 时,我将如何找到类 indent 的所有实例,直到类 highlight 的下一个实例>?

最佳答案

$('tr.highlight').click(function() {
var $indents = $(this).nextAll('tr.indent');
});

编辑

这似乎选择了所有 .indents 而不管 .highlights。试试这个:

$('tr.highlight').click(function() {
var row = $(this).next();
var selection = false;
while(row.hasClass('indent')) {
if(!selection) {
selection = row;
} else {
selection.add(row);
}
row = row.next();
}
});

关于javascript - 使用 jQuery,如何找到出现在另一个类之间的类的所有实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1868365/

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