问题描述:

I've been able to show/hide a div after checking any checkboxes. I've also been able to create a check all button that selects all of the checkboxes. The problem now is how will I link the two together?

When I hit check all, it doesn't show/hide the div I want to show/hide but works when you select each individually. Here is the page url

Bonus: If anyone can also make it so that the "select all" button changes to "deselect all" Thanks, community!

The script:

<script>

$('input[type=checkbox]').change(

function(){

if($('input[type=checkbox]').is(':checked')){

// if any of the checkboxes are checked then make the area visible

$('.send-control').fadeIn();

}else{

// only if all are unchecked will this fire and hide the area

$('.send-control').fadeOut();

}

});

$('#toggle-all').click(function() {

$('input[type="checkbox"]').prop('checked',true);

});

</script>

网友答案:

Try to add .change() to your method:

 $('input[type="checkbox"]').prop('checked',true).change();

As far as i know you have to call the change method manually because otherwise the change event wont be registered.

相关阅读:
Top