gpt4 book ai didi

javascript - 只允许选中一个(批准/拒绝)复选框

转载 作者:行者123 更新时间:2023-11-28 12:43:24 24 4
gpt4 key购买 nike

更新:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="chkbox_checked_uncheked.aspx.cs"
Inherits="Ediable_Repeater.chkbox_checked_uncheked" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="Scripts/jquery-1.6.2.min.js" type="text/javascript"></script>

<script type="text/javascript">

$(document).ready(function () {
$('#C1All').click(function () {
debugger
$('.col1').attr("checked", $('#C1All').attr("checked"));
$('.col2').removeAttr("checked");
$('#C2All').removeAttr("checked");
});

$('#C2All').click(function () {
debugger
$('.col2').attr("checked", $('#C2All').attr("checked"));
$('.col1').removeAttr("checked");
$('#C1All').removeAttr("checked");
});

$('.col1').each(function () {
$(this).click(function () {
var id = $(this).attr('id');
debugger
var coresId = id.replace('C1', 'C2');
$('#' + coresId).removeAttr("checked");
$('#C1All').removeAttr("checked");
$('#C2All').removeAttr("checked");
});
});

$('.col2').each(function () {
$(this).click(function () {
var id = $(this).attr('id');
var coresId = id.replace('C2', 'C1');
debugger
$('#' + coresId).removeAttr("checked");
$('#C1All').removeAttr("checked");
$('#C2All').removeAttr("checked");
});
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<div>
<table border="1">
<tr>
<td>
<asp:CheckBox ID="C1All" runat="server" class="col1" Text="approve all" />
</td>
<td>
<asp:CheckBox ID="C2All" runat="server" class="col2" Text="Reject all" />
</td>
</tr>
<tr>
<td>
<asp:CheckBox ID="C101" runat="server" class="col1" Text="john 0" />
</td>
<td>
<asp:CheckBox ID="C201" runat="server" class="col2" Text="john 0" />
</td>
</tr>
<tr>
<td>
<asp:CheckBox ID="C102" runat="server" class="col1" Text="john 1" />
</td>
<td>
<asp:CheckBox ID="C202" runat="server" class="col2" Text="john all" />
</td>
</tr>
<tr>
<td>
<asp:CheckBox ID="C103" runat="server" class="col1" Text="john 2" />
</td>
<td>
<asp:CheckBox ID="C203" runat="server" class="col2" Text="John 2" />
</td>
</tr>
</table>
</div>
</div>
</form>
</body>
</html>

我有两列(全部批准/拒绝全部),如何限制用户只允许每一列中的一个复选框?

这是屏幕的输出:

enter image description here

我尝试过类似的方法,但没有成功:

 function SelectApproveAllCheckboxes(chk, selector) 
{
$('#<%=gv.ClientID%>').find(selector + " input:checkbox").each(function ()
{
$(this).prop("checked", $(chk).prop("checked"));
});
}
function SelectRejectAllCheckboxes(chk, selector)
{
$('#<%=gv.ClientID%>').find(selector + " input:checkbox").each(function ()
{
$(this).prop("checked", $(chk).prop("checked"));
});
}

<asp:CheckBox ID="chkAll" runat="server" onclick="SelectApproveAllCheckboxes(this, '.approve)" />
<asp:CheckBox ID="chkAll1" runat="server" onclick="SelectRejectAllCheckboxes(this, '.reject)" />

最佳答案

不要使用复选框,而是使用单选按钮,它们是为此设计的。

关于javascript - 只允许选中一个(批准/拒绝)复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10560012/

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