<!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 id="Head1">
<title></title>
<script type="text/javascript">
var couponIdS = "";
var chbs;
var len; function fanxuan(obj) {
chbs = document.getElementsByName("ckb");
len = chbs.length;
aa(obj);
} function aa(obj) {
for (i = 0; i < len; i++) {
if (obj.value == chbs[i].title) {
chbs[i].checked = obj.checked;
aa(chbs[i]);
}
}
}
</script>
</head>
<body>
<form name="form1" method="post" id="form1">
<table border="1" align="left">
<tr>
<td style="width: 150px;">
名称
</td>
</tr>
<tr>
<td align="left">
<input type='checkbox' onclick='fanxuan(this)' title='' name='ckb' title='' value='1' />首页新闻
</td>
</tr>
<tr>
<td align="left">
<input type='checkbox' onclick='fanxuan(this)' title='1' name='ckb'
title='' value='3' />首页新闻右侧
</td>
</tr>
<tr>
<td>
<input type='checkbox' onclick='fanxuan(this)'
title='3' name='ckb' title='' value='4' />首页新闻右侧下面
</td>
</tr>
<tr>
<td align="left">
<input type='checkbox' onclick='fanxuan(this)'
title='3' name='ckb' title='' value='8' />首页新闻右侧下面2
</td>
</tr>
<tr>
<td align="left">
<input type='checkbox'
onclick='fanxuan(this)' title='8' name='ckb' title='' value='9' />首页新闻右侧下面2左侧
</td>
</tr>
<tr>
<td align="left">
<input
type='checkbox' onclick='fanxuan(this)' title='9' name='ckb' title='' value='16' />首页新闻右侧下面2左侧下面
</td>
</tr>
<tr>
<td align="left">
<input type='checkbox' onclick='fanxuan(this)' title='1' name='ckb'
title='' value='2' />首页新闻左侧
</td>
</tr>
<tr>
<td align="left">
<input type='checkbox' onclick='fanxuan(this)'
title='2' name='ckb' title='' value='7' />首页新闻左侧下面
</td>
</tr>
<tr>
<td align="left">
<input type='checkbox' onclick='fanxuan(this)' title='' name='ckb' title='' value='5' />圈子首页
</td>
</tr>
<tr>
<td align="left">
<input type='checkbox' onclick='fanxuan(this)' title='5' name='ckb'
title='' value='6' />圈子首页下面
</td>
</tr>
<tr>
<td align="left">
<input type='checkbox' onclick='fanxuan(this)' title='' name='ckb' title='' value='10' />圈子首页新闻
</td>
</tr>
<tr>
<td align="left">
<input type='checkbox' onclick='fanxuan(this)' title='10' name='ckb'
title='' value='11' />圈子首页新闻右侧
</td>
</tr>
</table>
</form>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1">
<title></title>
<script type="text/javascript">
var couponIdS = "";
var chbs;
var len; function fanxuan(obj) {
chbs = document.getElementsByName("ckb");
len = chbs.length;
aa(obj);
} function aa(obj) {
for (i = 0; i < len; i++) {
if (obj.value == chbs[i].title) {
chbs[i].checked = obj.checked;
aa(chbs[i]);
}
}
}
</script>
</head>
<body>
<form name="form1" method="post" id="form1">
<table border="1" align="left">
<tr>
<td style="width: 150px;">
名称
</td>
</tr>
<tr>
<td align="left">
<input type='checkbox' onclick='fanxuan(this)' title='' name='ckb' title='' value='1' />首页新闻
</td>
</tr>
<tr>
<td align="left">
<input type='checkbox' onclick='fanxuan(this)' title='1' name='ckb'
title='' value='3' />首页新闻右侧
</td>
</tr>
<tr>
<td>
<input type='checkbox' onclick='fanxuan(this)'
title='3' name='ckb' title='' value='4' />首页新闻右侧下面
</td>
</tr>
<tr>
<td align="left">
<input type='checkbox' onclick='fanxuan(this)'
title='3' name='ckb' title='' value='8' />首页新闻右侧下面2
</td>
</tr>
<tr>
<td align="left">
<input type='checkbox'
onclick='fanxuan(this)' title='8' name='ckb' title='' value='9' />首页新闻右侧下面2左侧
</td>
</tr>
<tr>
<td align="left">
<input
type='checkbox' onclick='fanxuan(this)' title='9' name='ckb' title='' value='16' />首页新闻右侧下面2左侧下面
</td>
</tr>
<tr>
<td align="left">
<input type='checkbox' onclick='fanxuan(this)' title='1' name='ckb'
title='' value='2' />首页新闻左侧
</td>
</tr>
<tr>
<td align="left">
<input type='checkbox' onclick='fanxuan(this)'
title='2' name='ckb' title='' value='7' />首页新闻左侧下面
</td>
</tr>
<tr>
<td align="left">
<input type='checkbox' onclick='fanxuan(this)' title='' name='ckb' title='' value='5' />圈子首页
</td>
</tr>
<tr>
<td align="left">
<input type='checkbox' onclick='fanxuan(this)' title='5' name='ckb'
title='' value='6' />圈子首页下面
</td>
</tr>
<tr>
<td align="left">
<input type='checkbox' onclick='fanxuan(this)' title='' name='ckb' title='' value='10' />圈子首页新闻
</td>
</tr>
<tr>
<td align="left">
<input type='checkbox' onclick='fanxuan(this)' title='10' name='ckb'
title='' value='11' />圈子首页新闻右侧
</td>
</tr>
</table>
</form>
</body>
</html>
问题是什么,
不过简单看了一遍,
每个checkbox都设定了2个title,
不知道这是什么用途。
可能是我技术不够吧,不明白这个写法的用途
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1">
<title></title>
<script type="text/javascript">
var chbs;
var len; function fanxuan(obj) {
chbs = document.getElementsByName("ckb");
len = chbs.length;
aa(obj);
} function aa(obj) {
for (i = 0; i < len; i++) {
if (obj.value == chbs[i].title) {
chbs[i].checked = obj.checked;
aa(chbs[i]);
}
}
}
</script>
</head>
<body> <table border="1" align="left">
<tr>
<td align="left">
<input type='checkbox' onclick='fanxuan(this)' title='' name='ckb' value='1' />父
</td>
</tr>
<tr>
<td align="left">
<input type='checkbox' onclick='fanxuan(this)' title='1' name='ckb'
value='3' />子1
</td>
</tr>
<tr>
<td align="left">
<input type='checkbox' onclick='fanxuan(this)' title='1' name='ckb'
value='2' />子2
</td>
</tr>
</table>
</body>
</html>
这是最简单的例子, 选中 父 , 俩个子 就选中, Tree 结构 用递归做 ,我有一个树形结构,现在要求选中父级以后,子级也自动选中。
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1">
<title></title>
<script type="text/javascript">
var couponIdS = "";
var chbs;
var len; function fanxuan(obj) {
chbs = document.getElementsByName("ckb");
len = chbs.length;
aa(obj);
} function aa(obj) {
for (var i = 0; i < len; i++) {
if (obj.value == chbs[i].title) {
chbs[i].checked = obj.checked;
aa(chbs[i]);
}
}
}
</script>
</head>
<body>
<form name="form1" method="post" id="form1">
<table border="1" align="left">
<tr>
<td style="width: 150px;">
名称
</td>
</tr>
<tr>
<td align="left">
<input type='checkbox' onclick='fanxuan(this)' title='' name='ckb' title='' value='1' />首页新闻
</td>
</tr>
<tr>
<td align="left">
<input type='checkbox' onclick='fanxuan(this)' title='1' name='ckb'
title='' value='3' />首页新闻右侧
</td>
</tr>
<tr>
<td>
<input type='checkbox' onclick='fanxuan(this)'
title='3' name='ckb' title='' value='4' />首页新闻右侧下面
</td>
</tr>
<tr>
<td align="left">
<input type='checkbox' onclick='fanxuan(this)'
title='3' name='ckb' title='' value='8' />首页新闻右侧下面2
</td>
</tr>
<tr>
<td align="left">
<input type='checkbox'
onclick='fanxuan(this)' title='8' name='ckb' title='' value='9' />首页新闻右侧下面2左侧
</td>
</tr>
<tr>
<td align="left">
<input
type='checkbox' onclick='fanxuan(this)' title='9' name='ckb' title='' value='16' />首页新闻右侧下面2左侧下面
</td>
</tr>
<tr>
<td align="left">
<input type='checkbox' onclick='fanxuan(this)' title='1' name='ckb'
title='' value='2' />首页新闻左侧
</td>
</tr>
<tr>
<td align="left">
<input type='checkbox' onclick='fanxuan(this)'
title='2' name='ckb' title='' value='7' />首页新闻左侧下面
</td>
</tr>
<tr>
<td align="left">
<input type='checkbox' onclick='fanxuan(this)' title='' name='ckb' title='' value='5' />圈子首页
</td>
</tr>
<tr>
<td align="left">
<input type='checkbox' onclick='fanxuan(this)' title='5' name='ckb'
title='' value='6' />圈子首页下面
</td>
</tr>
<tr>
<td align="left">
<input type='checkbox' onclick='fanxuan(this)' title='' name='ckb' title='' value='10' />圈子首页新闻
</td>
</tr>
<tr>
<td align="left">
<input type='checkbox' onclick='fanxuan(this)' title='10' name='ckb'
title='' value='11' />圈子首页新闻右侧
</td>
</tr>
</table>
</form>
</body>
</html>