首页 > 其他 > 详细

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

时间:2015-02-03 20:55:43      阅读:249      评论:0      收藏:0      [点我收藏+]

作用相当于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>

 

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

原文:http://www.cnblogs.com/songxia/p/4270797.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!