gpt4 book ai didi

javascript - 取消选中一个复选框时如何取消选中以下所有复选框

转载 作者:太空宇宙 更新时间:2023-11-03 22:44:41 26 4
gpt4 key购买 nike

我有一组已标记的动态复选框。当我单击其中一个时,应取消选中下面的所有复选框,如果再次标记,则再次标记上面的所有复选框。请问有人可以帮我吗?

谢谢。

@for (int i = 0; i < Model.transportDate.Count(); i++)
{
<tr>
<td>
@Html.CheckBoxFor(Model => Model.transportDate[i].selection)
</td>
<td>
@Html.TextBoxFor(Model => Model.transportDate[i].Date)
</td>
</tr>
}

Overview of question

最佳答案

您可以使用 javascript 在客户端执行此操作。参见示例。

$('#tbl [type=checkbox]').click(function() {
var $this = this; //save clicked chk
if ($(this).is(':checked')) //nothing to do
return;
var uncheck = false;
$(this).parents('table') //get container
.find('[type=checkbox]') //get siblings
.each(function() { //iterate
if (this === $this) //found
uncheck = true;
if (uncheck)
this.checked = false; //clear checkbox
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table id="tbl">
<tr>
<td><input type="checkbox" checked="checked" /></td>
<td>other</td>
</tr>
<tr>
<td><input type="checkbox" checked="checked" /></td>
<td>other</td>
</tr>
<tr>
<td><input type="checkbox" checked="checked" /></td>
<td>other</td>
</tr>
<tr>
<td><input type="checkbox" checked="checked" /></td>
<td>other</td>
</tr>
<tr>
<td><input type="checkbox" checked="checked" /></td>
<td>other</td>
</tr>
<tr>
<td><input type="checkbox" checked="checked" /></td>
<td>other</td>
</tr>
<tr>
<td><input type="checkbox" checked="checked" /></td>
<td>other</td>
</tr>
<tr>
<td><input type="checkbox" checked="checked" /></td>
<td>other</td>
</tr>
<tr>
<td><input type="checkbox" checked="checked" /></td>
<td>other</td>
</tr>
<tr>
<td><input type="checkbox" checked="checked" /></td>
<td>other</td>
</tr>
</table>

关于javascript - 取消选中一个复选框时如何取消选中以下所有复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50571809/

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