读书人

jquery 单击子复选框改变下一级复选框

发布时间: 2012-09-13 09:51:53 作者: rapoo

jquery 单击子复选框改变上一级复选框的状态
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jquery 在属性 中传变量 </title>
<script type="text/javascript" src="jquery-1.3.1.js"></script>
<script type="text/javascript">
$(document).ready(function(){
var zc="zi".length; //zi在类属性class标识是子复选框 复到字符串的长度 和标识的 fu 长度是一样的 在这里共用一个
$(":checkbox").click(function() { //单击复选框 触发事件函数
var checkbox=$(this);
var name=$(this).attr("class");
var b1=name.substring(zc,name.length); //得到所单击的这个复选框后缀的数字组合
var bb=$(this).attr("checked"); //判断选中或未选中 true or false
var b="fu"+b1; //父 复选框class 的组合
var a = "zi"+b1; //子复选框class的组合
var b22=$('td input[border="0" cellspacing="0" cellpadding="0">
<tr>
<td scope="col">父选框<input type="checkbox" /> </td>
</tr>
<tr>
<td>苹果<input type="checkbox" /></td>
</tr>
<tr>
<td>香蕉<input type="checkbox" /></td>
</tr>
<tr>
<td>桔子<input type="checkbox" ></td>
</tr>

<tr>
<td scope="col">父选框<input type="checkbox" /> </td>
</tr>
<tr>
<td>苹果<input type="checkbox" /></td>
</tr>
<tr>
<td>香蕉<input type="checkbox" /></td>
</tr>
<tr>
<td>桔子<input type="checkbox" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript" src="jquery-1.3.1.js"></script>
<script type="text/javascript">
$(function(){
$('[type=checkbox]').click(function (){
$('.fu').each(function(){
var sign = $(this).attr('sign');
var flag = true;
$('.zi'+sign).each(function(){
//alert($(this).attr('names'));
if($(this).attr("checked")){
//alert('aaa');
//alert("dddd"+sign );
flag= false;

}

});
if(flag){
//alert($(this).attr('checked'));
$(this).attr('checked',false);
//alert("dddd"+sign );
flag= true;
} else {
$(this).attr('checked',true);
flag= true;
}


});}) ;

});
</script>.
</head>

<body>
<table width="200" border="0" cellspacing="0" cellpadding="0">
<tr>
<td scope="col">父选框<input type="checkbox" sign="1"/> </td>
</tr>
<tr>
<td>苹果<input type="checkbox" names="苹果"/></td>
</tr>
<tr>
<td>香蕉<input type="checkbox" names="香蕉"/></td>
</tr>
<tr>
<td>桔子<input type="checkbox" names="桔子"/></td>
</tr>

<tr>
<td scope="col">父选框<input type="checkbox" sign="2"/> </td>
</tr>
<tr>
<td>苹果<input type="checkbox" names="香蕉" /></td>
</tr>
<tr>
<td>桔子<input type="checkbox" names="桔子"></td>
</tr>
</table>

</body>
</html>










读书人网 >Web前端

热点推荐