簡體   English   中英

使用全選腳本過濾表

[英]Using select all script for filtered table

我正在使用此處的文件 )腳本,並且正在使用第一行中的所有腳本檢查我的復選框。 但是首先,當我篩選列時,此腳本也選擇了隱藏行中的復選框。

$(document).ready(function(){
$('#select_all').on('click',function(){
    if(this.checked){
        $('.checkbox').each(function(){
            this.checked = true;
        });
    }else{
         $('.checkbox').each(function(){
            this.checked = false;
        });
    }
});

$('.checkbox').on('click',function(){
    if($('.checkbox:checked').length == $('.checkbox').length){
        $('#select_all').prop('checked',true);
    }else{
        $('#select_all').prop('checked',false);
    }
});
});

感謝您的幫助。

使用jQuery :visible選擇器可以忽略已過濾的復選框。 https://api.jquery.com/visible-selector/

$('#select_all').on('click',function(){
    var doCheck = this.checked;
    $('.checkbox:visible').each(function(){
         this.checked = doCheck;
    });
});

是的 我的新代碼:

$(document).ready(function(){
$('#select_all').on('click',function(){
    if(this.checked){
        $('.checkbox:visible').each(function(){
            this.checked = true;
        });
    }else{
         $('.checkbox:visible').each(function(){
            this.checked = false;
        });
    }
});

$('.checkbox:visible').on('click',function(){
    if($('.checkbox:checked').length == $('.checkbox:visible').length){
        $('#select_all').prop('checked',true);
    }else{
        $('#select_all').prop('checked',false);
    }
});
});

謝謝大家...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM