function CheckBoxList_Click(sender) 
{
var container = sender.parentNode; 
if(container.tagName.toUpperCase() == "TD")
{ // 服务器控件设置呈现为 table 布局(默认设置),否则使用流布局
container = container.parentNode.parentNode; // 层次: <table><tr><td><input />
}
var chkList = container.getElementsByTagName("input");
var senderState = sender.checked;
for(var i=0; i<chkList.length;i++)
{
chkList[i].checked = false;
}
sender.checked = senderState;
}
<h3>单选效果的 CheckBoxList</h3>
<div style="float:left">
<h4>静态项</h4>
<asp:CheckBoxList ID="CheckBoxList1" BorderWidth="1" runat="server" RepeatLayout="Flow">
<asp:ListItem onclick="CheckBoxList_Click(this)" Value="Item1">Item1</asp:ListItem>
<asp:ListItem onclick="CheckBoxList_Click(this)" Value="Item2">Item2</asp:ListItem>
<asp:ListItem onclick="CheckBoxList_Click(this)" Value="Item3">Item3</asp:ListItem>
<asp:ListItem onclick="CheckBoxList_Click(this)" Value="Item4">Item4</asp:ListItem>
<asp:ListItem onclick="CheckBoxList_Click(this)" Value="Item5">Item5</asp:ListItem>
</asp:CheckBoxList>
</div>
<div style="float:left;padding-left:100px">
<h4>绑定项</h4>
<asp:CheckBoxList ID="CheckBoxList2" BorderWidth="1" runat="server" DataTextField="Value" DataValueField="Key" OnDataBound="CheckBoxList2_DataBound">
</asp:CheckBoxList>
</div>
单选CheckBoxList实现
本文介绍了一种利用ASP.NET CheckBoxList控件实现单选效果的方法。通过JavaScript函数`CheckBoxList_Click`来控制CheckBox的行为,使其在点击时具备单选功能。文章提供了具体的HTML和JavaScript代码示例。

被折叠的 条评论
为什么被折叠?



