代码之家  ›  专栏  ›  技术社区  ›  John Madden

带复选框的JQuery下一个同级

  •  0
  • John Madden  · 技术社区  · 13 年前

    我有一个由第三方工具生成的代码,看起来像这样:

    <tr id="abc0">
      <td class="ABC" id="abc0_def">
        <input onclick="..." type="checkbox" />
      <td class="BodySpacer">
      <td class="ABC" id"abc0_hij">
        <input onclick="..." type="checkbox" />
    <tr id="abc1">
      <td class="ABC" id="abc1_def">
        <input onclick="..." type="checkbox" />
      <td class="BodySpacer">
      <td class="ABC" id"abc1_hij">
        <input onclick="..." type="checkbox" />
    

    正如你所看到的,td标签没有正确关闭,我无法控制这一点。

    对于中的复选框 abcX_def 我如何自动勾选复选框 abcX_hij ?

    我尝试过:

    var n = $(this).parent().nextAll().has(":checkbox").first().find(":checkbox");
    n.attr("checked","checked");
    

    但这似乎不起作用。

    1 回复  |  直到 13 年前
        1
  •  0
  •   Arun P Johny    13 年前

    尝试

    $(this).closest('tr').find(':checkbox').not(this).prop('checked', $(this).is('checked'))
    

    演示: Fiddle