Created
March 17, 2015 12:58
-
-
Save terehof/fc4d6444eca3e97e06e4 to your computer and use it in GitHub Desktop.
группа чекбоксов (когда отмечаешь главный, дочерние тоже отмечаются)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('body').on('change','[data-group]',function(){ | |
var is_main = $(this).data('group-main'); | |
is_main = is_main || 0; | |
var group = $(this).data('group'); | |
var is_checked; | |
// Если дернули главный чекбокс | |
if(is_main) | |
{ | |
// если его отметили, то отметим все дочерние | |
is_checked = false; | |
if($(this).is(':checked')) | |
{ | |
is_checked = true; | |
} | |
$('[data-group="'+group+'"]').prop('checked',is_checked); | |
} | |
else | |
{ | |
var child = $('[data-group="'+group+'"]').not('[data-group-main]'); | |
is_checked = false; | |
if(child.size() == child.filter(':checked').size()) | |
{ | |
is_checked = true; | |
} | |
$('[data-group-main][data-group="'+group+'"]').prop('checked',is_checked); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment