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>




  • 相关阅读:
    C 库函数 ------ qsort()
    递归之美
    C函数库 ------ ctype.h
    scanf 多行输入判断结束
    POSIX库、glibc库、pthreads库、libc库、newlib、uClibc
    Docker 私有仓库搭建
    在daemon.json中配置主机后无法启动docker
    MySQL配置HeartBeat实现心跳监控和浮动IP
    Heartbeat基础知识-运维小结
    (二) Docker中启动镜像
  • 原文地址:https://www.cnblogs.com/cniteeq/p/2292707.html
Copyright © 2011-2022 走看看