首页 > 技术文章 > checkbox多选、全选js效果

wei-dong 2017-09-20 13:35 原文

//全选checkbox
    function allCheck() {
         //全选input
        var all = $("input[name='all']");
        //全部的input type="checkbox"
        var checboxs = $(".ys_manage_tbody input[name='checkbox']");
         //选中的input type="checkbox"
        var rchecbox = $(".ys_manage_tbody input[name='checkbox']:checked");

        //取消全选
        checboxs.click(function(){
            if(checboxs.length != rchecbox.length) {
                all.removeAttr("checked",false);
            }
            if(checboxs.length == rchecbox.length) {
                all.prop("checked",true);
            }
        });

        //全选操作
        all.click(function () {
            var check = $(this).is(":checked");
            if(check) {
                checboxs.prop("checked",true);
            } else {
                checboxs.removeAttr("checked",false);
            }
        })
    }                 

 

 

推荐阅读