2 回答

TA貢獻(xiàn)1836條經(jīng)驗(yàn) 獲得超5個(gè)贊
我會(huì)將一個(gè)函數(shù)綁定到復(fù)選框,然后在此函數(shù)中,如果選中了復(fù)選框,您將找到closest父級(jí)<tr>并將每個(gè)子級(jí)設(shè)為只讀(不要擔(dān)心復(fù)選框本身,您仍然可以再次取消選中它們。更多信息這個(gè))<input><tr><input>
試試這個(gè)片段
$("table input.makeReadOnly").change(function (){
if($(this).prop("checked")){
$(this).closest("tr").find("input").prop("readonly", true);
} else {
$(this).closest("tr").find("input").prop("readonly", false);
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<table>
<tbody>
<tr>
<td><input></td>
<td><input></td>
<td><input class="makeReadOnly" type="checkbox"></td>
</tr>
<tr>
<td><input></td>
<td><input></td>
<td><input class="makeReadOnly" type="checkbox"></td>
</tr>
</tbody>
</table>

TA貢獻(xiàn)1829條經(jīng)驗(yàn) 獲得超13個(gè)贊
您可以遍歷頁面上的復(fù)選框,然后從那里導(dǎo)航到 tr 屬性?但是,如果沒有任何代碼示例,很難理解,而且我對(duì) SO 太陌生,無法發(fā)表評(píng)論。
var inputs = form.getElementsByTagName("input");
for (var i = 0; i < inputs.length; i++) {
if ($(inputs[i]).type == "checkbox" && $(inputs[i]).is(':checked')){
$(inputs[i]).closest('tr').prop('readonly', true);
}
}
可能太冗長并且可能會(huì)被追捕,但我認(rèn)為它可能會(huì)有所幫助!
- 2 回答
- 0 關(guān)注
- 170 瀏覽
添加回答
舉報(bào)