我在开发公司oa系统的时候.想找一个csdn的菜单.可是网上有这样的代码.可是不是基于数据库,也不能按权限管理.我就写了一个.我的这个.只有一个程序文件和一个数据库.文件很少,也很容易查错.但是功能完全实现了!
数据库结构:
table:menu
id
parentid,int,4
menuname,char,20
link,char,50
table:userlevel
id
userid,int,4
menuid,int,4
-------------------------------------程序源文件:menulist.asp------------------------------
<%
'-------------------------------'
'源创商务策划有限公司-oa系统
'模块名称:可权限控制的菜单
'-------------------------------'
set conn = server.createobject("adodb.connection")
conn.open("provider=microsoft.jet.oledb.4.0;data source="+server.mappath("tree.mdb")+";persist security info=false")
%>
<html>
<head>
<title> dstree </title>
<style>
body,td{font:12px verdana}
#treebox{background-color:#fffffa;}
#treebox .ec{margin:0 5 0 5;}
#treebox .hasitems{font-weight:bold;height:20px;padding:3 6 0 6;margin:2px;cursor:hand;color:#555555;border:1px solid #fffffa;}
#treebox .items{height:20px;padding:3 6 0 6;margin:1px;cursor:hand;color:#555555;border:1px solid #fffffa;}
</style>
<script>
//code by star 20003-4-7
var hc = "color:#990000;border:1px solid #cccccc";
var sc = "background-color:#efefef;border:1px solid #cccccc;color:#000000;";
var io = null;
function inittree(){
var rootn = document.all.menuxml.documentelement;
var sd = 0;
document.onselectstart = function(){return false;}
document.all.treebox.appendchild(createtree(rootn,sd));
}
function createtree(thisn,sd){
var nodeobj = document.createelement("span");
var upobj = document.createelement("span");
with(upobj){
style.marginleft = sd*10;
classname = thisn.haschildnodes()?"hasitems":"items";
innerhtml = "<img src=expand.gif class=ec>" + thisn.getattribute("text") +"";
onmousedown = function(){
if(event.button != 1) return;
if(this.getattribute("cn")){
this.setattribute("open",!this.getattribute("open"));
this.cn.style.display = this.getattribute("open")?"inline":"none";
this.all.tags("img")[0].src = this.getattribute("open")?"expand.gif":"contract.gif";
}
if(io){
io.runtimestyle.csstext = "";
io.setattribute("selected",false);
}
io = this;
this.setattribute("selected",true);
this.runtimestyle.csstext = sc;
}
onmouseover = function(){
if(this.getattribute("selected"))return;
this.runtimestyle.csstext = hc;
}
onmouseout = function(){
if(this.getattribute("selected"))return;
this.runtimestyle.csstext = "";
}
oncontextmenu = contextmenuhandle;
onclick = clickhandle;
}
if(thisn.getattribute("treeid") != null){
upobj.setattribute("treeid",thisn.getattribute("treeid"));
}
if(thisn.getattribute("href") != null){
upobj.setattribute("href",thisn.getattribute("href"));
}
if(thisn.getattribute("target") != null){
upobj.setattribute("target",thisn.getattribute("target"));
}
nodeobj.appendchild(upobj);
nodeobj.insertadjacenthtml("beforeend","<br>")
if(thisn.haschildnodes()){
var i;
var nodes = thisn.childnodes;
var cn = document.createelement("span");
upobj.setattribute("cn",cn);
if(thisn.getattribute("open") != null){
upobj.setattribute("open",(thisn.getattribute("open")=="true"));
upobj.getattribute("cn").style.display = upobj.getattribute("open")?"inline":"none";
if( !upobj.getattribute("open"))upobj.all.tags("img")[0].src ="contract.gif";
}
for(i=0;i<nodes.length;cn.appendchild(createtree(nodes[i++],sd+1)));
nodeobj.appendchild(cn);
}
else{
upobj.all.tags("img")[0].src ="endnode.gif";
}
return nodeobj;
}
window.onload = inittree;
</script>
<script>
function clickhandle(){
if((this.getattribute("href")!=null)&&(this.getattribute("href")!="http://"))
{parent.mainframe.location.href=this.getattribute("href");} //在mainframe窗口打开连接。
}
function contextmenuhandle(){
event.returnvalue = false;