首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

checkboxlist能不能只能单选?该如何解决

2012-03-15 
checkboxlist能不能只能单选?checkboxlist能不能只能单选?有没有什么属性做控制的?还是不行啊?[解决办法]

checkboxlist能不能只能单选?
checkboxlist能不能只能单选?有没有什么属性做控制的?还是不行啊?

[解决办法]
就是要你单选^_^

<!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> Untitled Page </title>
<script type= "text/javascript ">
function CheckBoxList_Click(sender)
{
var ndx = sender.id.lastIndexOf( "_ ");
var tblId = sender.id.slice(0, ndx);
var tbl = document.getElementById(tblId);
var eles = tbl.getElementsByTagName( "input ");
var senderState = sender.checked;
for(var i=0; i <eles.length;i++) {
eles[i].checked = false;
}
sender.checked = senderState;
}
</script>
</head>
<body>
<form id= "form1 " runat= "server ">
<div>
<asp:CheckBoxList ID= "CheckBoxList1_1 " BorderWidth= "1 " runat= "server ">
<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:CheckBoxList>
</div>
</form>
</body>
</html>

热点排行