Check and Uncheck Checkbox Dynamically with jQuery : bug?

前端 未结 5 2245
我在风中等你
我在风中等你 2021-02-13 02:08

I made a script in order to control master & slave checkboxes (automatic checking and unchecking).

Here is my JS :

$(document).ready(function() {

           


        
5条回答
  •  清歌不尽
    2021-02-13 02:37

    I wrote you a plugin for this:

    $.fn.dependantCheckbox = function() {
      var $targ = $(this);
      function syncSelection(group, action) {
        $targ.each(function() {
          if ($(this).data('checkbox-group') === group) {
            $(this).prop('checked', action);
          }
        });
      };
      $('input[type="checkbox"][data-checkbox-group]').on('change', function() {
        var groupSelection = $(this).data('checkbox-group');
        var isChecked = $(this).prop('checked');
        syncSelection(groupSelection, isChecked);
      });
    }
    $('input[type="checkbox"][data-checkbox-group]').dependantCheckbox();
    
    
    
    
    
    
    
    
    
    
    

    http://codepen.io/nicholasabrams/pen/mJqyqG

提交回复
热议问题