0

我目前正在开发一个引导 x 可编辑表。我需要在表行中选择具有给定命名类的所有节点并触发它们的 .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 结构下的表行中的给定类来选择元素?

4

1 回答 1

2

你拼写closest错误。改为closest('tr')并做一个find()

$('.myButton').click(function(){
     // only this row of 'myeditable' should be selected
     $(this).closest('tr')
          .find('.myeditable').editable('submit', {....}); 
});

此外,editable()它不是一个 jQuery 函数。你在使用一些插件吗?

于 2013-09-06T02:26:43.297 回答