jQuery 树遍历的最佳方法?
我得到以下代码:
<table border=1>
<tbody>
<tr>
<td>issue</td>
<td><a class="issueDrawer" href="#">view</a></td>
<td>description</td>
</tr>
<tr class="issueDrawer" style="display: none;"><td colspan="100%">boom!</td></tr>
<tr>
<td>issue</td>
<td><a class="issueDrawer" href="#">view</a></td>
<td>description</td>
</tr>
<tr class="issueDrawer" style="display: none;"><td colspan="100%">boom!</td></tr>
<tr>
<td>issue</td>
<td><a class="issueDrawer" href="#">view</a></td>
<td>description</td>
</tr>
<tr class="issueDrawer" style="display: none;"><td colspan="100%">boom!</td></tr>
</tbody>
</table>
基本上,我正在对“a.issueDrawer”执行操作,该操作应该为“tr.issueDrawer”设置动画。从“a.issueDrawer”,我目前正在执行 $(this).parent().parent().next(),但必须有一种更清晰的方法来遍历并找到第一个“tr.issueDrawer”。
想法?
I got the following code:
<table border=1>
<tbody>
<tr>
<td>issue</td>
<td><a class="issueDrawer" href="#">view</a></td>
<td>description</td>
</tr>
<tr class="issueDrawer" style="display: none;"><td colspan="100%">boom!</td></tr>
<tr>
<td>issue</td>
<td><a class="issueDrawer" href="#">view</a></td>
<td>description</td>
</tr>
<tr class="issueDrawer" style="display: none;"><td colspan="100%">boom!</td></tr>
<tr>
<td>issue</td>
<td><a class="issueDrawer" href="#">view</a></td>
<td>description</td>
</tr>
<tr class="issueDrawer" style="display: none;"><td colspan="100%">boom!</td></tr>
</tbody>
</table>
Basically I'm performing an action on "a.issueDrawer" which should animate "tr.issueDrawer". From "a.issueDrawer" I'm currently doing $(this).parent().parent().next(), but there must be a cleaner way to travers up and find the first "tr.issueDrawer".
Thoughts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
.closest 代替
。.parent().parent()
('tr')Instead of
.parent().parent()
, you can use.closest('tr')
.