Javascript JQuery-如何查找具有特定类的元素的下一次出现
我有一张这样的桌子:Javascript JQuery-如何查找具有特定类的元素的下一次出现,javascript,jquery,html,Javascript,Jquery,Html,我有一张这样的桌子: <table id="TblProduits" class="TblProduitsLayout"> <thead> <tbody> <tr class="placeholderRow"> <td> <input class="PrixUnitr" type="number" />
<table id="TblProduits" class="TblProduitsLayout">
<thead>
<tbody>
<tr class="placeholderRow">
<td>
<input class="PrixUnitr" type="number" />
</td>
<tr class="placeholderRow">
<tr class="placeholderRow SousTotal">
<td>
<input class="MontnHT" type="text" disabled="disabled" min="0"/>
</td>
<tr class="placeholderRow">
<tr class="placeholderRow SousTotal">
<td>
<input class="MontnHT" type="text" disabled="disabled" min="0">
</td>
</tbody>
</table>
$('body').on('change', '.PrixUnitr', function() {
$(this).closest('tr').nextAll("tr.SousTotal").find("input.MontnHT").val("foo");
});
我的问题是,还更改了TR
中包含的具有相同类名SousTotal
的其他输入,因为我只想更改第一次出现的情况,我做错了什么?如何修复它呢?使用.first()
或.eq(0)
获取元素的第一次出现
$(this).closest('tr').nextAll("tr.SousTotal").first().find("input.MontnHT:first").val("foo");
或
.next(“tr.SousTotal”)
或.find(“input.MontnHT:first”)
阅读我已经尝试过的文档中nextAll所做的事情。next()只检查下一个tr元素,不继续探索restI已经检查过的nextAll(),我知道这可能不是最好的方法。我不认为这很容易,我花了两个小时在这上面,你是一头野兽,我的好先生(y)
$(this).closest('tr').nextAll("tr.SousTotal:eq(0)").find("input.MontnHT:eq(0)").val("foo");