jquery实现checkbox级联选择

  1. <html>  
  2. <head>  
  3. </head>  
  4. <body>  
  5. <dt>    
  6. <!--<img src="/crm/images/tree/tree_node_e_2.gif" /><img src="/crm/images/tree/folder_off.gif" />   -->  
  7. <span class="text-g">     
  8. <input type="checkbox" name="functionIds" value='1' style="margin:3px 0 0;" index='1'/>    
  9. <span style="margin-left:3px">建立活動</span>    
  10. </span>    
  11. </dt>    
  12. <dt>    
  13. <!-- <img src="/crm/images/tree/tree_vert.gif" /><img src="/crm/images/tree/tree_node_n_0.gif" />    
  14. <img src="/crm/images/tree/item.gif" />  -->  
  15. <input type="checkbox" name="functionIds" value='2' style="margin:3px 0 0;" index='1_1'/>    
  16. <span style="margin-left:3px">設定客戶群</span>:    
  17. <input type="checkbox" name="functionIds" value='3' style="margin:3px 0 0;" index='1_1_1'  />基金    
  18. <input type="checkbox" name="functionIds" value='4' style="margin:3px 0 0;" index='1_1_2'  />信用卡    
  19. <input type="checkbox" name="functionIds" value='5' style="margin:3px 0 0;" index='1_1_3'  />黃金存摺    
  20. </dt>    
  21. <dt>    
  22. <!--<img src="/crm/images/tree/tree_vert.gif" /><img src="/crm/images/tree/tree_node_n_0.gif" />    
  23. <img src="/crm/images/tree/item.gif" />   -->  
  24. <input type="checkbox" name="functionIds" value='6' style="margin:3px 0 0;" index='1_2'/>    
  25. <span style="margin-left:3px">訂定活動</span>:    
  26. <input type="checkbox" name="functionIds" value='7' style="margin:3px 0 0;" index='1_2_1'  />基金    
  27. <input type="checkbox" name="functionIds" value='8' style="margin:3px 0 0;" index='1_2_2'  />信用卡    
  28. <input type="checkbox" name="functionIds" value='9' style="margin:3px 0 0;" index='1_2_3'  />黃金存摺    
  29. </dt>    
  30. <dt>    
  31. <!-- <img src="/crm/images/tree/tree_vert.gif" /><img src="/crm/images/tree/tree_node_e_0.gif" />    
  32. <img src="/crm/images/tree/item.gif" />  -->  
  33. <input type="checkbox" name="functionIds" value='10' style="margin:3px 0 0;" index='1_3'/>    
  34. <span style="margin-left:3px">活動計劃</span>    
  35. </dt>    
  36. <dt>    
  37. </body>  
  38. </html>  
  1. <script type="text/javascript" src="jquery-1.6.4.js"></script>  
  2. <script>  
  3.     $(function(){    
  4.         $(":checkbox").click(function(){    
  5.             var index = $(this).attr("index");              
  6.             $(":checkbox[index^="+index+"]").attr("checked",$(this).is(":checked"));                
  7.             var parent_index = index.substring(0,index.length - 2);    
  8.             $(":checkbox[index="+parent_index+"]").attr("checked",false);               
  9.             var parentIsCheck = false;    
  10.             $(":checkbox[index^="+parent_index+"]").each(function(i){           
  11.                 if($(this).is(":checked")){    
  12.                     parentIsCheck = true;    
  13.                 }    
  14.             });             
  15.             $(":checkbox[index="+parent_index+"]").attr("checked",parentIsCheck);    
  16.             var parent_parent_index = index.substring(0,parent_index.length - 2);               
  17.             var parent_parent_is_check = false;    
  18.             $(":checkbox[index="+parent_parent_index+"]").attr("checked",parent_parent_is_check);    
  19.             $(":checkbox[index^="+parent_parent_index+"]").each(function(i){                
  20.                 if($(this).is(":checked")){    
  21.                     parent_parent_is_check = true;    
  22.                 }    
  23.             });             
  24.             $(":checkbox[index="+parent_parent_index+"]").attr("checked",parent_parent_is_check);    
  25.         });    
  26.     });    
  27. </script> 
转载自:https://blog.csdn.net/cai7095576/article/details/21484019
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值