zoukankan      html  css  js  c++  java
  • 判断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>




  • 相关阅读:
    20150112-夜深,人不静
    20150111-谁会记得
    20150110-我希望我的歌声里都是希望
    20150102-霰现
    20150116-卵子
    20150109-放弃了一切希望
    20150105-条大路哟
    笔记:使用 stylus stylus-loader
    如何处理烫伤的伤口?
    连电子硬件行业都在开始使用 Git 了你还在等什么?
  • 原文地址:https://www.cnblogs.com/cniteeq/p/2292707.html
Copyright © 2011-2022 走看看