【发布时间】:2013-09-06 10:26:43
【问题描述】:
我目前正在开发一个引导 x 可编辑表。我需要选择所有具有给定类WITHIN 的节点并触发它们的.editable()。这是我的 jquery 选择器代码。
<table class="table table-bordered">
<thead>
.............
</thead>
<tr>
<td><a class="myeditable editable-user" data-type="select" href="#">user...</a></td>
<td><a class="myeditable editable-date" data-type="date" href="#">date...</a></td>
<td><a class="myeditable editable-user" data-type="text" href="#">description..</a></td>
<td><span class="actions"><a class="myButton" href="#">submit changes</a></span></td>
</tr>
<tr>
.......... the same contents as above
</tr>
</table>
我的脚本应该是这样的:
$('.myButton').click(function(){
// only this row of 'myeditable' should be selected
$(this).closet('td')
.siblings.children('.myeditable').editable('submit', {....});
});
谁能有更好的解决方案来按我的 Html 结构下的表格行中的给定类选择元素?
【问题讨论】:
-
壁橱应该是最接近的,并且在一个方法中是兄弟姐妹。
$(this).closest('td').siblings().children('.myeditable')它应该可以工作。或者只是做$(this).closest('tr').find('.myeditable') -
感谢 PSL。这是一个错字。它是一种魅力。
标签: jquery twitter-bootstrap jquery-selectors