簡體   English   中英

更改一個表行中的所有復選框

[英]change all checkboxes in one table-row

我想取消選中一個表行中的所有復選框。 我有這個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) } )

實現的問題是,您正在設置TD元素的checked屬性,而不是checkbox

您可以直接使用:checkbox選擇器 ,然后設置其checked屬性

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

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> 

請嘗試以下操作:

 $("#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> 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM