JS遍历原理,一个父复选框按钮被选后,所有子复选框按钮也全部选中

JS遍历原理,一个父复选框按钮被选后,所有子复选框按钮也全部选中

 1 json数据格式:{$item.shop_id}=["61676515","74460904"]
 2 
 3 <input  checked="checked"  type = "checkbox" name="shop_type_set[]" value ="{$item.id}" shop_id='{$item.shop_id}' class="shop_type_set">
 4 
 5 <input  {if $item.checked==1} checked="checked" {/if} type = "checkbox" name="shop_id[]" value ="{$item.shop_id}" id="{$item.shop_id}" shop_type_set="{$item.shop_type_set}" class="set_shop">
 6 
 7 $(".shop_type_set").click(function(){
 8         var shop_id =JSON.parse($(this).attr('shop_id')) ;
 9         var checked = $(this).prop("checked");
10         set_shop(shop_id,checked);
11         set_goods_remove();
12     });
13 
14 $('.shop_type_set').each(function(i,v){
15         var checked = $(this).prop("checked");
16         if(checked==true){
17             var shop_id =JSON.parse($(this).attr('shop_id')) ;
18             set_shop(shop_id,checked);
19         }
20     
21     });
22 function set_shop(shop_id,checked){
23         $(shop_id).each(function(i,v){
24             $(".set_shop").each(function(){
25                 shop_one = $(this).val();
26                 if(shop_one==v){
27                     $(this).prop("checked",checked);
28                 }
29                 
30             });
31             
32         });
33     }
原文地址:https://www.cnblogs.com/meetuj/p/8868088.html