使用 select 所有脚本过滤 table
Using select all script for filtered table
我正在使用 this (file here) 脚本,并且正在使用检查第一行中的所有脚本来获取我的复选框。但首先,当我过滤一列时,此脚本也选中了隐藏行的复选框。
$(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);
}
});
});
谢谢大家...
我正在使用 this (file here) 脚本,并且正在使用检查第一行中的所有脚本来获取我的复选框。但首先,当我过滤一列时,此脚本也选中了隐藏行的复选框。
$(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);
}
});
});
谢谢大家...