JS实现CheckBoxList单选

<asp:CheckBoxList ID="ckPro_Support" runat="server"></asp:CheckBoxList>

这是后台绑定数据的Checkboxlist控件;

//实现checkboxlist单选
        window.onload = function () {
            var cbl = document.getElementById('<%= ckPro_Support.ClientID %>');
            var inputs = cbl.getElementsByTagName("input");           
            for (var i = 0; i < inputs.length; i++)
            {
                if (inputs[i].type == "checkbox")
                {
                    inputs[i].onclick = function ()
                    {
                        var cbs = inputs;
                        for (var i = 0; i < cbs.length; i++)
                        {
                            if (cbs[i].type == "checkbox" && cbs[i] != this && this.checked)
                            {
                                cbs[i].checked = false;
                            }
                        }
                    }
                }
            }

 

你可能感兴趣的:(JS实现CheckBoxList单选)