更改一个表格行中的所有复选框

时间:2017-03-29 07:59:36

标签: javascript jquery html checkbox

我想取消选中一个表格行中的所有复选框。 我有这个HTML代码:

<tr id="unlosta_line_1">
     <td>
        <input id="unlosta_prop_id_1" name="unlosta_prop_id[1]" value="1"  checked="checked" type="checkbox">
Feld 1
     </td>

     <td>
        <input id="unlosta_prop_id_2" name="unlosta_prop_id[2]" value="2"  type="checkbox">
Feld 2
     </td>

     <td>
        <input id="unlosta_prop_id_3" name="unlosta_prop_id[3]" value="3"  type="checkbox">
Feld 3
     </td>
     <td>...and so on
     <td>
</tr>

我现在尝试的是这个jquery代码:

$("tr#unlosta_line_1").children("td").each(function(i) { $(i).prop("checked", false) } )

3 个答案:

答案 0 :(得分:2)

您实施的问题在于,您设置的checked元素的TD属性不是checkbox

您可以直接使用:checkbox selector,然后设置其checked属性

$("#unlosta_line_1 :checkbox").prop("checked", false);

答案 1 :(得分:0)

inputtd

的孩子

(function (){
$("#unlosta_line_1").children("td").each(function(i) {
      $(this).children('input').attr("checked", false)
      })
      })()
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tr id="unlosta_line_1">
  <td>
    <input id="unlosta_prop_id_1" name="unlosta_prop_id[1]" value="1"  type="checkbox"> Feld 1
  </td>

  <td>
    <input id="unlosta_prop_id_2" name="unlosta_prop_id[2]" value="2" type="checkbox"> Feld 2
  </td>

  <td>
    <input id="unlosta_prop_id_3" name="unlosta_prop_id[3]" value="3" type="checkbox"> Feld 3
  </td>
  <td>...and so on
    <td>
</tr>
</table>

答案 2 :(得分:0)

尝试以下方法:

$("#unlosta_line_1 :checkbox").prop("checked", false);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
    <tr id="unlosta_line_1">
       <td>
          <input id="unlosta_prop_id_1" name="unlosta_prop_id[1]" value="1"  checked="checked" type="checkbox">
  Feld 1
       </td>

       <td>
          <input id="unlosta_prop_id_2" name="unlosta_prop_id[2]" value="2"  type="checkbox">
  Feld 2
       </td>

       <td>
          <input id="unlosta_prop_id_3" name="unlosta_prop_id[3]" value="3"  type="checkbox">
  Feld 3
       </td>
       <td>...and so on
       <td>
  </tr>
</table>

相关问题