gpt4 book ai didi

javascript - 禁用 html 表格最后一行复选框

转载 作者:行者123 更新时间:2023-11-28 15:18:41 25 4
gpt4 key购买 nike

如果表中只有一行或最后一行,我试图在两个条件下禁用该复选框,但它不明白为什么它不禁用。

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;

最佳答案

您可以使用prop() 设置禁用属性或使用 [0] 获取 dom 元素并设置 disabled 属性

$('#table_forms tr:last input[type="checkbox"]').prop('disabled', true);
<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>

$('#table_forms tr:last input[type="checkbox"]')[0].disabled = true;
<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>

关于javascript - 禁用 html 表格最后一行复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32479017/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com