判断Repeater 下嵌套绑定的CheckBoxList和RadioButtonList控件是否选中(答题)


js验证Repeater 下嵌套绑定的CheckBoxList和RadioButtonList控件每组中是否有至少1个被选中。

CheckBoxList默认显示成表格结构 设置RepeatLayout="UnorderedList"让其生成的代码为如下结构。

 <dd>
<span id="ContentPlaceHolder1_repList_RadList_1">
<input id="ContentPlaceHolder1_repList_RadList_1_0_1" type="radio" name="ctl00$ContentPlaceHolder1$repList$ctl02$RadList" value="A" />
<label for="ContentPlaceHolder1_repList_RadList_1_0_1">111</label>
<input id="ContentPlaceHolder1_repList_RadList_1_1_1" type="radio" name="ctl00$ContentPlaceHolder1$repList$ctl02$RadList" value="B" />
<label for="ContentPlaceHolder1_repList_RadList_1_1_1">222</label>
<input id="ContentPlaceHolder1_repList_RadList_1_2_1" type="radio" name="ctl00$ContentPlaceHolder1$repList$ctl02$RadList" value="C" />
<label for="ContentPlaceHolder1_repList_RadList_1_2_1">333</label>
</span>
</dd>

 

<asp:CheckBoxList ID="CheckBoxList1" runat="server" RepeatLayout="UnorderedList">
</asp:CheckBoxList>
<script type="text/javascript">
$(document).ready(function () {
$("#form1").submit(function () {
var counts = 0;
$("dd span").each(function () {
var fload = false;
var nodes = this.childNodes;
for (var i = 0; i < nodes.length; i++) {
if (nodes[i].type == "radio"||nodes[i].type=="checkbox") {
if (nodes[i].checked) {
fload = true;
}
}
}
if (fload) {
counts++;
}
});
counts = $("dd").length - counts;
if (counts > 0) {
alert("您有" + counts + "题未答!");
return false;
}
});
});
</script>




转载于:https://www.cnblogs.com/cniteeq/archive/2011/12/18/2292707.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值