zoukankan      html  css  js  c++  java
  • JS checkbox 全选 全不选

    /*
        JS checkbox 全选 全不选
        
        Html中checkbox: <input type="checkbox" name="cbx" value="<%= Default by yourself %>"/>
        以下方法各有优劣,使用时根据情况而定.
    */
    
    //全选(方法一:each 循环)
    function checkAll() {
        $.each($("input[name=cbx]"), function(i) {
            if ($(this).attr("checked") == false) {
                $(this).attr("checked", "true");
            }
        });
    }
    
    //全选(方法二:根据名称)
    function checkAll() {
        var code_Values = document.all['cbx'];
        if(code_Values.length){
            for(var i=0;i<code_Values.length;i++){
                code_Values[i].checked = true;
            }
        }else{
            code_Values.checked = true;
        }
    }
    
    //全选(方法三:根据Tag 和 Type [input中的type])
    function checkAll() {
        var code_Values = document.getElementsByTagName("input");
        if (code_Values.length) {
            for (i = 0; i < code_Values.length; i++) {
                if (code_Values[i].type == "checkbox") {
                    code_Values[i].checked = true;
                }
            }
        } else {
            if (code_Values.type == "checkbox") {
                code_Values.checked = true;
            }
        }
    }
    
    //全不选(方法一:each 循环)
    function uncheckAll() {
        $.each($("input[name=cbx]"), function(i) {
            if ($(this).attr("checked") == true) {
                $(this).attr("checked", "false");
            }
        });
    }
    
    //全不选(方法二:根据名称)
    function uncheckAll()
    {
        var code_Values = document.all['cbx'];
        if(code_Values.length){
        for(var i=0;i<code_Values.length;i++){
            code_Values[i].checked = false;
        }
        }else{
            code_Values.checked = false;
        }
    }
    
    //全不选(方法三:根据Tag 和 Type [input中的type])
    function uncheckAll() {
        var code_Values = document.getElementsByTagName("input");
        if (code_Values.length) {
            for (i = 0; i < code_Values.length; i++) {
                if (code_Values[i].type == "checkbox") {
                    code_Values[i].checked = false;
                }
            }
        } else {
            if (code_Values.type == "checkbox") {
                code_Values.checked = false;
            }
        }
    }
  • 相关阅读:
    Qt之界面数据存储与获取(使用setUserData()和userData())
    UML中关联(Association)、聚合(Aggregation)和合成(Composition)之间的区别
    Entity Framework Model First下改变数据库脚本的生成方式
    keepalive学习
    函数、极限、连续
    C#集合基础与运用
    面向查询服务的参数化查询
    WinDbg 命令手册
    知识管理方法论
    项目管理Project
  • 原文地址:https://www.cnblogs.com/preacher/p/3905015.html
Copyright © 2011-2022 走看看