jQuery实现目录树

<!--不支持IE-->
<html>
	<head><title>tree</title></head>
	<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
	<script type="text/javascript">
		$(function(){
			$('#tree_ul').find('label').click(function(){
				$(this).siblings('ul').toggle();
			});
			$('#sel_all_cb').click(function(){
				$('input[name="resourceIds"]').prop('checked',this.checked);
			});
			
			$('input[name="resourceIds"]').click(function(){
				$(this).siblings('ul').find('input').prop('checked',this.checked);
				if(this.checked){
					$(this).parents('li').children('input').prop('checked',this.checked);
				//当前选中的菜单,未选中
				}else{
					var temp = $(this);
					var count = 1;
					//有上级就循环
					while(temp.parent().parent().parent().is('li')){
						//看看兄弟菜单是不是都没选中,如果都没选中,那么父菜单也要设置未选中
						var flag = true;
						temp.parent().siblings('li').children('input').each(function(i){
							if(this.checked){flag = false;}
						});
						temp = temp.parent().parent().prev();
						if(flag){
							temp.removeProp('checked');
						}else{
							break;
						}
					}
				}
			});
		});
	</script>
	<body>
		全选<input type="checkbox" id="sel_all_cb"  value="">
		<ul id="tree_ul">
			<li>
				<label>系统管理</label><input type="checkbox"  name="resourceIds" value="">
				<ul>
					<li>
					    <label>用户管理</label><input type="checkbox"  name="resourceIds"  value="">
						<ul>
							<li><label>增加</label><input type="checkbox"  name="resourceIds"  value=""></li>
							<li><label>删除</label><input type="checkbox"  name="resourceIds"  value=""></li>
							<li><label>修改</label><input type="checkbox"  name="resourceIds"  value=""></li>
							<li><label>查询</label><input type="checkbox"  name="resourceIds"  value=""></li>
						</ul>
					</li>
					<li>
						<label>角色管理</label><input type="checkbox"   name="resourceIds" value="">
						<ul>
							<li><label>增加</label><input type="checkbox"  name="resourceIds"  value=""></li>
							<li><label>删除</label><input type="checkbox"  name="resourceIds"  value=""></li>
							<li><label>修改</label><input type="checkbox"  name="resourceIds"  value=""></li>
							<li><label>查询</label><input type="checkbox"  name="resourceIds"  value=""></li>
						</ul>
					</li>
					<li>
						<label>资源管理</label><input type="checkbox"  name="resourceIds"  value="">
						<ul>
							<li><label>增加</label><input type="checkbox"  name="resourceIds"  value=""></li>
							<li><label>删除</label><input type="checkbox"  name="resourceIds"  value=""></li>
							<li><label>修改</label><input type="checkbox"  name="resourceIds"  value=""></li>
							<li><label>查询</label><input type="checkbox"  name="resourceIds"  value=""></li>
						</ul>
					</li>
				</ul>
			</li>
			
			<li>
				<label>电子商务</label><input type="checkbox"  name="resourceIds"  value="">
				<ul>
					<li><label>产品管理</label><input type="checkbox" name="resourceIds"   value="">
						<ul>
							<li><label>增加</label><input type="checkbox"  name="resourceIds"  value=""></li>
							<li><label>删除</label><input type="checkbox"  name="resourceIds"  value=""></li>
							<li><label>修改</label><input type="checkbox"  name="resourceIds"  value=""></li>
							<li><label>查询</label><input type="checkbox"  name="resourceIds"  value=""></li>
						</ul>
					</li>
					<li><label>交易管理</label><input type="checkbox"  name="resourceIds"  value="">
						
					</li>
				</ul>
			</li>
			
			
		</ul>
		
	</body>
</html>

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值