我试图在两个条件下禁用复选框,如果表格或最后一行只有一行但是没有得到它为什么不禁用。
HTML:
<table id="table_forms">
<tr>
<td><input type="checkbox" class="chkView"/>View</td>
</tr>
<tr>
<td><input type="checkbox" class="chkView"/>View</td>
</tr>
</table>
JS:
$('#table_forms tr:last input[type="checkbox"]').disabled;
答案 0 :(得分:4)
您可以使用 prop()
设置已停用的属性,或使用[0]
获取dom元素并设置disabled
属性
$('#table_forms tr:last input[type="checkbox"]').prop('disabled', true);
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<table id="table_forms">
<tr>
<td>
<input type="checkbox" class="chkView" />View</td>
</tr>
<tr>
<td>
<input type="checkbox" class="chkView" />View</td>
</tr>
</table>
&#13;
或
$('#table_forms tr:last input[type="checkbox"]')[0].disabled = true;
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<table id="table_forms">
<tr>
<td>
<input type="checkbox" class="chkView" />View</td>
</tr>
<tr>
<td>
<input type="checkbox" class="chkView" />View</td>
</tr>
</table>
&#13;
答案 1 :(得分:0)
试试这个:
$('#table_forms tr:last input[type="checkbox"]').attr('disabled','disabled');