62,266
社区成员
发帖
与我相关
我的任务
分享 <table id="CheckBoxList1" border="0">
<tr>
<td><span selectvalue="aa"><input id="CheckBoxList1_0" type="checkbox" name="CheckBoxList1$0" /><label for="CheckBoxList1_0">1</label></span></td>
</tr><tr>
<td><span selectvalue="bb"><input id="CheckBoxList1_1" type="checkbox" name="CheckBoxList1$1" /><label for="CheckBoxList1_1">2</label></span></td>
</tr><tr>
<td><span selectvalue="cc"><input id="CheckBoxList1_2" type="checkbox" name="CheckBoxList1$2" /><label for="CheckBoxList1_2">3</label></span></td>
</tr>
</table><head runat="server">
<title>无标题页</title>
<script type="text/javascript">
function getSelectCkb()
{
var object = document.getElementById("CheckBoxList1");
var chkInput = object.getElementsByTagName("INPUT");
var chkLable = object.getElementsByTagName("Label");
var chkSpan = object.getElementsByTagName("span");
for(var i=0;i <chkInput.length;i++)
{
if(chkInput[i].checked)
{
alert(chkSpan[i].selectvalue);
}
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:CheckBoxList ID="CheckBoxList1" runat="server">
</asp:CheckBoxList><input type=button onclick="getSelectCkb()" />
</div>
</form>
</body>
</html>
ListItem item1,item2,item3;
item1 = new ListItem("1", "aa");
item1.Attributes.Add("selectvalue", "aa");
item2 = new ListItem("2", "bb");
item2.Attributes.Add("selectvalue", "bb");
item3 = new ListItem("3", "cc");
item3.Attributes.Add("selectvalue", "cc");
CheckBoxList1.Items.Add(item1);
CheckBoxList1.Items.Add(item2);
CheckBoxList1.Items.Add(item3);for (i = 0; i < number; i++)
{
if (document.getElementByID("checkboxlistName_" + i ).checked)
{
//do something
}
}