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>




  • 相关阅读:
    LeetCode_374. Guess Number Higher or Lower
    LeetCode_371. Sum of Two Integers
    LeetCode_367. Valid Perfect Square
    LeetCode_350. Intersection of Two Arrays II
    LeetCode_349. Intersection of Two Arrays
    LeetCode_345. Reverse Vowels of a String
    LeetCode_344. Reverse String
    LeetCode_342. Power of Four
    hadoop生态系统的详细介绍
    hadoop启动jobhistoryserver
  • 原文地址:https://www.cnblogs.com/cniteeq/p/2292707.html
Copyright © 2011-2022 走看看