Skip to content

Instantly share code, notes, and snippets.

@terehof
Created March 17, 2015 12:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save terehof/fc4d6444eca3e97e06e4 to your computer and use it in GitHub Desktop.
Save terehof/fc4d6444eca3e97e06e4 to your computer and use it in GitHub Desktop.
группа чекбоксов (когда отмечаешь главный, дочерние тоже отмечаются)
$('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