js-全选应用

代码不多,就当是记录自己的成长吧,欢迎讨论和指导!

主要功能:全部删除及全选功能,当全部选择是 ,全选框自动勾选,当不足

//批量删除选择
$("#checkAll").on("click",function(){
    var checkBox=$("input[name='delete']");
    if($("#checkAll").is(":checked")){
        for(var i = 0; i < checkBox.length; i++) {
            checkBox[i].checked = "true";
        }
    }
    else{
        checkBox.removeAttr("checked");
    }
});
//如果不全选中 取消 全选的选中项
$("#visitordiv").on("click","input[name='delete']",function(){
    var checkBox=$("input[name='delete']");    
    var isCheckAll=true;
    for(var i = 0; i < checkBox.length; i++) {
        if($(checkBox[i]).is(":checked")==false){
            $("#checkAll").removeAttr("checked");
            isCheckAll=false;
        }
    }
    if(isCheckAll){
        $("#checkAll")[0].checked = "true";
    }
});
//批量删除 删除
$("#DeleteAll").on("click",function(){
    var checkBox=$("input[name='delete']");        
    confirmPop("您确定删除吗?", "确定要删除这个游客资料吗?", function(r) {
        if(r) {
            for(var i=0;i<checkBox.length;i++){
                if($(checkBox[i]).is(":checked")){
                    $(checkBox[i]).parent().parent().remove();
                }
            }  
            $("#checkAll").removeAttr("checked");
        }
    },{"green":"Yes","red":"No"});
});

 

posted @ 2017-03-08 14:52  虫牙抱抱  阅读(191)  评论(0编辑  收藏  举报