ASP.NET CheckBoxList 控件实现全选、反选、清除功能 利用js

直接看代码:

JS代码如下:

<script type="text/javascript" language="javascript">
        function checkAll() {
            
            for (var i = 0; i < document.getElementById("cblStatuteEnumTypeId").getElementsByTagName("input").length; i++) {

                document.getElementById("cblStatuteEnumTypeId_" + i).checked = true;
            }
        }

        function deleteAll() {

            for (var i = 0; i < document.getElementById("cblStatuteEnumTypeId").getElementsByTagName("input").length; i++) {

                document.getElementById("cblStatuteEnumTypeId_" + i).checked = false;
            }
        }

        function ReverseAll() {

            for (var i = 0; i < document.getElementById("cblStatuteEnumTypeId").getElementsByTagName("input").length; i++) {

                var objCheck = document.getElementById("cblStatuteEnumTypeId_" + i);

                if (objCheck.checked)

                    objCheck.checked = false;
                else
                    objCheck.checked = true;
            }
        }

    </script>

 checkboxlist控件:

<asp:CheckBoxList ID="cblStatuteEnumTypeId" runat="server">
       <asp:ListItem Value="1">不是废止依据</asp:ListItem>
       <asp:ListItem Value="2">表格乱</asp:ListItem>
       <asp:ListItem Value="3">缺表格</asp:ListItem>
       <asp:ListItem Value="4">缺内容</asp:ListItem>
       <asp:ListItem Value="5">废止人工识别</asp:ListItem>
       <asp:ListItem Value="6">确定是修订依据</asp:ListItem>
       <asp:ListItem Value="7">无法规标题清单</asp:ListItem>
</asp:CheckBoxList>

 JS按钮调用代码:

 <input type="button" onclick="checkAll()" value="全选" /> 
1 <input type="button" onclick="ReverseAll()" value="反选" id="Button1" /> 
1 <input type="button" onclick="deleteAll()" value="取消" /> 

 

你可能感兴趣的:(checkbox)