jquery_笔记(父子checkbox,条件选择)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
<meta charset=utf-8 />  
<!--[if IE]>  
  <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>  
<![endif]-->  
 <script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>  
<script type="text/javascript">
function SelectBox(){
	$("input[type=checkbox]").attr("checked","checked");
	}
	function UnSelectBox(){
	$("input[type=checkbox]").attr("checked",null);
	}
	//----------------非常神奇而又简单的----------------
	function goSelect(id){
			var arr = id.split("_");
			var superid = arr[0] + "_"+ arr[0];
			//alert("测试"+arr[0]+"    "+arr[1]);
			if(arr[0] != arr[1]){
				//如果点击子类复选框,则父类的复选框处于选中状态
				if($("#"+id)[0].checked){
					//组织父类id
					$("#"	+ superid).attr("checked","checked");
				}else{
					var flag = false;
					//过滤选择1,checkbox2,以arr[0]开头,3,不以arr[0]结尾的checkbox
					var $child = $("input[type = checkbox][id ^="+arr[0]+" ]:not([id $="+arr[0]+"])");
					$child.each(function(index,DomEle){
					//	alert();
						if(this.checked){
							flag = true;
							return;
						}
					});
					
					if(!flag){
						$("#"+superid).attr("checked",null);
					}
				}
			}

					if(arr[0] == arr[1]){
						if($("#"+id)[0].checked){
					//	alert("yyy");
							$("input[type = checkbox][id ^="+arr[0]+"]").attr("checked","checked");
						}else{
								$("input[type = checkbox][id ^="+arr[0]+"]").attr("checked",null);
						}
					}
	}
</script>
<style>  
  article, aside, figure, footer, header, hgroup,   
  menu, nav, section { display: block; }  
</style>  
  <title>rsl </title>
 </head>

 <body>
<table>
<tr>
	<td>
<input type="button" value="全选" οnclick="SelectBox();">
<input type="button" value="全不选" οnclick="UnSelectBox();">
	</td>
</tr>
<tr>
	<td>
	<fieldset>
		<legend>
			<input type="checkbox" name="menuModule" value="company,company" id="company_company" onClick="goSelect(this.id);" title="客户管理" >客户管理
		</legend>
		<div id="" class="">
					<input type="checkbox" name="menuModule" value="company,base" id="company_base" onClick="goSelect(this.id);" title="客户拜访" >客户拜访
		</div>
		<div id="" class="">
					<input type="checkbox" name="menuModule" value="company,linkMan" id="company_linkMan" onClick="goSelect(this.id);" title="联系人" >联系人
		</div>
		<div id="" class="">
				<input type="checkbox" name="menuModule" value="company,linkTouch" id="company_linkTouch" onClick="goSelect(this.id);" title="联系记录" >联系记录
		</div>
		<div id="" class="">
				<input type="checkbox" name="menuModule" value="company,rule" id="company_rule" onClick="goSelect(this.id);" title="客户设置" >客户设置
		</div>
	</fieldset>
	</td>
</tr>
<tr>
	<td>
		<fieldset width="888">
		<legend>
			<input type="checkbox" name="menuModule" value="report,report" id="report_report" onClick="goSelect(this.id);" title="报表分析" >报表分析
		</legend>
		<div id="" class="">
					<input type="checkbox" name="menuModule" value="report,kufx" id="report_kufx" onClick="goSelect(this.id);" title="客户分析" >客户分析
		</div>
		<div id="" class="">
					<input type="checkbox" name="menuModule" value="report,kufl" id="report_kufl" onClick="goSelect(this.id);" title="客户分类" >客户分类
		</div>
			</td>
	</fieldset>
</tr>
</table>
 </body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值