2015-09-29 23 views
0

我正在使用thisfile here)腳本,我正在使用檢查我的複選框的第一行中的所有腳本。但是,首先當我篩選一列時,該腳本也在隱藏行中選中了複選框。使用select過濾表的所有腳本

$(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); 
    } 
}); 
}); 

感謝您的幫助。

+0

可以共享相關的HTML代碼呢? – Sushil

+0

試試'$('。複選框:可見')' – Malk

+0

@Malk,這個工作完美。謝謝... – zokanzi

回答

0

是的。我的新代碼:

$(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); 
    } 
}); 
}); 

謝謝大家......

0

使用jQuery :visible選擇器省略已被過濾的複選框。 https://api.jquery.com/visible-selector/

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