<!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>
jquery_笔记(父子checkbox,条件选择)
最新推荐文章于 2024-04-13 18:31:23 发布