jQuery 在匹配后返回第二个表格单元格?
该代码有效,但我认为它锚定在错误的标签上。这里我相信它是说在 aaaaa 的第一场比赛中,返回下一个 div 的单元格值,因为它恰好在潜水中。但现在我也想在一场比赛中拉出第三个 td 的值。如何更改此代码,以便在找到匹配项时可以使用它获取两个后续单元格。
var bodyprefix = $('#issuetbl td:contains(aaaa)').siblings().find('div').html();
例如,给定 aaaa,我想要 var1=whatever 和 var2=cccc
我可以运行两次,但想要基于索引或第 n 个子项的相同函数。
<tr>
<td>aaaa</td>
<td><div>whatever</div></td>
<td>cccc</td>
</tr>
<tr>
<td>1111</td>
<td><div>something</div></td>
<td>2222</td>
</tr>
This code is working, but I think it's anchoring on the wrong tag. Here I believe it's saying on the first match of aaaaa, return the cell value for the next div, because it happens to be under a dive. But now that I also want to pull the value of 3rd td on a match. How can I change this code so that I can use it get both of the subsequent cells when a match is found.
var bodyprefix = $('#issuetbl td:contains(aaaa)').siblings().find('div').html();
For example, given aaaa, I want var1=whatever and var2=cccc
I'm okay with running it twice, but would like the same function based on index or nth-child.
<tr>
<td>aaaa</td>
<td><div>whatever</div></td>
<td>cccc</td>
</tr>
<tr>
<td>1111</td>
<td><div>something</div></td>
<td>2222</td>
</tr>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
nextAll
而不是siblings
:bodyprefixes
现在是所有值的数组。Use
nextAll
instead ofsiblings
:bodyprefixes
is now an array of all the values.这比您出于说明目的所要求的部分多一点,但具有更大的灵活性:
This is a little more than what you asked for with portions for illustrative purposes, but allows for more flexibility: