【问题标题】:How to select all named class within a table row in jquery如何在jquery中选择表行中的所有命名类
【发布时间】: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


【解决方案1】:

你拼错了closest。改为closest('tr') 并改为find()

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

另外,editable() 不是 jQuery 函数。你在用什么插件吗?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-07-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-13
    • 1970-01-01
    • 2013-10-10
    相关资源
    最近更新 更多