checkbox权限树
html代码
<html>
<head>
<title>dtree</title>
<link rel="StyleSheet" href="dtree.css" type="text/css" />
<script type="text/javascript" src="dtree.js"></script>
</head>
<body>
<div class="dtree">
<p><a href="javascript: d.openAll();">open all</a> | <a href="javascript: d.closeAll();">close all</a></p>
<script type="text/javascript">
<!--
d = new dTree('d');
d.add(0,-1,'菜单权限树');
d.add(1,0,'authority','25','一级菜单1 ');
d.add(2,1,'authority','26','二级菜单1 ');
d.add(3,2,'authority','27','三级菜单1 ');
d.add(4,2,'authority','28','三级菜单2 ');
d.add(32,3,'authority','26','二级菜单1 ');
d.add(33,32,'authority','27','用户管理 ');
d.add(34,32,'authority','28','用户组管理 ');
d.add(22,1,'authority','26','二级菜单1 ');
d.add(23,22,'authority','27','用户管理 ');
d.add(24,22,'authority','28','用户组管理 ');
d.add(6,0,'authority','25','一级菜单2 ',true,true);
d.add(7,6,'authority','26','二级菜单2 ',true,true);
d.add(8,7,'authority','27','用户管理 ',true,true);
d.add(9,7,'authority','28','用户组管理 ',true,true);
d.add(11,0,'authority','25','一级菜单3 ');
d.add(12,11,'authority','26','二级菜单3 ');
d.add(13,12,'authority','27','用户管理 ');
d.add(14,12,'authority','27','用户组管理 ');
document.write(d);
d.openAll();
//-->
</script>
</div>
<div>
<input type='button' name='bTest' value='test' οnclick='test();'>
</div>
</body>
<script type="text/javascript">
<!--
function test(){
var count = 0;
var obj = document.all.authority;
for(i=0;i<obj.length;i++){
if(obj[i].checked){
alert(obj[i].value);
count ++;
}
}
}
//-->
</script>
</html>
dtree.js 关键代码
Node这个方法 里解释了 各个参数的含义
function Node(id, pid, cname, cvalue, cshow, cchecked, cdisabled, url, title, target, icon, iconOpen, open) { this.id = id; this.pid = pid; //chechbox的名称 this.cname = cname; //chechbox的值 this.cvalue = cvalue; //chechbox的显示 this.cshow = cshow; //chechbox是否被选中,默认是不选 this.cchecked = cchecked||false; //chechbox是否可用,默认是可用 this.cdisabled = cdisabled||false; //节点链接,默认是虚链接 this.url = url||'#'; this.title = title; this.target = target; this.icon = icon; this.iconOpen = iconOpen; this._io = open || false; this._is = false; this._ls = false; this._hc = false; this._ai = 0; this._p; };
具体的使用可以下载附件查看代码.......反正挺简单的....