jQuery处理点击父级checkbox所有子级checkbox都选中,取消选中所有子级checkbox都取消
2015-11-19 15:06
357 查看
注意,每个foreach标签内部都加一个div用来区分各个层次关系,模板代码如下:
以下是jQuery代码:
<foreach name='node' item='v'> <div class='a' align='center' style='padding-bottom:10px;color:#0000EE'> {$v.title} <input type="checkbox" name='access[]' level='1' value='{$v.id}_1' <if condition='$v["access"]'>checked='checked'</if>> <foreach name='v.child' item='value'> <div class='b'> <li style='list-style-type:none;font-size:14px;padding-top:5px;color:#8B1A1A'> {$value.title} <input type="checkbox" name='access[]' level='2' value='{$value.id}_2' <if condition='$value["access"]'>checked='checked'</if>></li> <foreach name='value.child' item='value1'> <div class='c'> <li style='list-style-type:none;font-size:13px;padding-top:5px;color:#8E8E38'>{$value1.title} <input type="checkbox" name='access[]' level='3' value='{$value1.id}_3' <if condition='$value1["access"]'>checked='checked'</if>></li> </div> </foreach> </div> </foreach> </div> </foreach>
以下是jQuery代码:
<script src='__PUBLIC__/js/jquery-1.6.4.min.js'></script> <script> $(function(){ $('[level=1]').click(function(){ if(this.checked){ $(this).parent().find('input').prop('checked','checked'); } else{ $(this).parent().find('input').removeAttr('checked'); } }); $('[level=2]').click(function(){ if (this.checked) { $(this).parent().parent().find('input').prop('checked','checked'); } else{ $(this).parent().parent().find('input').removeAttr('checked'); } }); }); </script>
相关文章推荐
- jquery easy UI datagrid+action错误分析
- DOM对象和JQuery对象的区别
- 参数 of jQuery.ajax()
- 使用jquery ajaxForm提交表单
- Jquery实现仿京东商城省市联动菜单
- JQuery datepicker 用法
- Jquery制作--焦点图左右轮播
- 跨域请求之jQuery的ajax jsonp的使用
- jquery的ajax和getJson跨域获取json数据
- jQuery日期和时间插件(jquery-ui-timepicker-addon.js)中文破解版使用
- dataType of jQuery.ajax()
- jquery动画
- jquery实现页面局部刷新
- jquery_DOM笔记3
- jquery_DOM笔记2
- jquery 中post 、get的同步问题
- 详细解读Jquery各Ajax函数:$.get(),$.post(),$.ajax(),$.getJSON()
- (JQuery)如何做到搜索输入框的数据异步提交
- 15款jQuery带缩略图的图片轮播切换特效代码
- 15款jQuery带缩略图的图片轮播切换特效代码