• 在CheckBox中,仅仅允许选择一项


    作用相当于RadioButonList

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <script type="text/javascript">
            function UncheckOthers(objchkbox) {
                //Get the parent control of checkbox which is the checkbox list
                var objchkList = objchkbox.parentNode.parentNode.parentNode;
                //Get the checkbox controls in checkboxlist
                var chkboxControls = objchkList.getElementsByTagName("input");
                //Loop through each check box controls
                for (var i = 0; i < chkboxControls.length; i++) {
                    //Check the current checkbox is not the one user selected
                    if (chkboxControls[i] != objchkbox && objchkbox.checked) {
                        //Uncheck all other checkboxes
                        chkboxControls[i].checked = false;
                    }
                }
            }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <asp:CheckBoxList ID="CheckBoxList1" runat="server">
                    <asp:ListItem Text="FirstValue" Value="1" onclick="UncheckOthers(this);">
                    </asp:ListItem>
                    <asp:ListItem Text="Second Value" Value="2" onclick="UncheckOthers(this);">
                    </asp:ListItem>
                    <asp:ListItem Text="Third Value" Value="3" onclick="UncheckOthers(this);">
                    </asp:ListItem>
                    <asp:ListItem Text="Fourth Value" Value="4" onclick="UncheckOthers(this);">
                    </asp:ListItem>
                    <asp:ListItem Text="Fifth Value" Value="5" onclick="UncheckOthers(this);">
                    </asp:ListItem>
                </asp:CheckBoxList>
            </div>
        </form>
    </body>
    </html>
    
  • 相关阅读:
    身份证验证(c#和js)
    获取焦点问题
    关于加载设计器遇到一个或多个错误问题的解决方案
    关于如何使用自定义的结束消息循环的方式 (转载)
    多种重要源码下载
    关于线程同步(转载)
    ArrayList的使用技巧
    一些所谓有利于家庭生活的优点
    080801 30℃
    080731 31℃
  • 原文地址:https://www.cnblogs.com/songxia/p/4270797.html
Copyright © 2020-2023  润新知