我正在使用一个表,每行包含一个复选框,而我提交我想要未选中的行被禁用这是我试图我创建一个表和行包含输入类型检查输入类型未选中表示我想要禁用该行所以当我在mvc中检索时,我可以得到详细信息
<table id="subjectTable">
<tbody><tr><input type='checkbox' name='subjectcheck' /></tr></tbody>
</table>
$("input:not(:checked)").each(function () {
$(this).closest('tr').attr("disabled", "true");
});
这个我怎么试过可以任何一个帮助
如果你想简单地删除<tr>
,你可以使用jQuery方法.closest()
和.remove()
:
$('input:not(:checked)')
选择输入<tr>
与.closest('tr')
.remove()
删除它们PS:请记住,你必须在你的<td>
内有一个<tr>
,否则你的<input>
将放在你的<table>
之外。
$('button').on('click', function(){
$('input:not(:checked)').closest('tr').remove();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table id="subjectTable">
<tbody>
<tr><td><input type='checkbox' name='subjectcheck' /></td></tr>
</tbody>
</table>
<button>Emulate submit !</button>
要删除未经检查的tr
的父tr,请尝试.parent()
和.remove()
,如下所示:
$("input:not(:checked)").each(function () {
$(this).parent('tr').remove();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table id="subjectTable">
<tbody>
<tr>
<input type='checkbox' name='subjectcheck'/>
</tr>
</tbody>
</table>