树状下拉菜单 - 51windows.Net
51windows.Net
>
技术文档
>
Web开发
>
ASP
>
Code Sample
>
目录结构示例代码
> 树状下拉菜单
树状下拉菜单
来自:
51windows.Net
作者:海娃
关键字
:菜单,tree,select
多级目录树下拉菜单演示:
/Asp_samples/tree/selecttree.asp
用法:
dbtreeselect.asp代码:
<% '使用方法<SCRIPT LANGUAGE="JavaScript" src="dbtreeselect.asp?id=id&pid=pid&text=text&table=table&sname=selectname&s_v=1&child=0/1"></SCRIPT> dim db_id,db_pid,db_text,db_table,select_name,select_value,dbpath db_id = request("id") db_pid = request("pid") '父ID db_text = request("text") '名 db_table = request("table") '表名 select_name = request("s_name") '下拉菜单名 select_value = trim(request("s_v")) '值 MustChildFolder = Request("child") '是否必须选择没有子类的分类 %> <!--#include file='conn.asp'--> /**************************************************** * 原作者: Fason(阿信)[蒲佛信] * http://fason.nease.net/ * pufoxin@hotmail.com * --------------------------------------------- * 数据库版修改:51windows(海娃) * http://www.51windows.Net ****************************************************/ var select_value = "<% = select_value %>" function TreeView(obj,target){ this.obj=obj; this.root=new node(-1); this.nodes=[] this.currentNode=null; this.html="" this.config={ blank :'┣━', line :'┣━' } for(i in this.config){var tem=this.config[i];this.config[i]=new Image();this.config[i].txt=tem} } function node(id,pid,txt){ this.id=id this.pid=pid this.txt=txt this.indent="" this.open=false; this.lastNode=false; this.hasNode=false } TreeView.prototype.add=function(id,pid,txt){ var itemTxt=txt?txt:"New Item" this.nodes[this.nodes.length]=new node(id,pid,itemTxt) } TreeView.prototype.DrawTree=function(pNode){ var str="" for(var i=0;i<this.nodes.length;i++){ if(this.nodes[i].pid==pNode.id){ str+=this.DrawNode(this.nodes[i].id,i) } } return str } TreeView.prototype.ChkPro=function(pNode){ var last; for(var n=0;n<this.nodes.length;n++){ if(this.nodes[n].pid==pNode.id)pNode.hasNode=true; if (this.nodes[n].pid == pNode.pid) last= this.nodes[n].id; } if (last==pNode.id) pNode.lastNode = true; } TreeView.prototype.DrawNode=function(id,nid){ var str="" var select_ed = "" var nNode=this.nodes[nid] this.DrawLine(nNode,nNode) if(nNode.hasNode) nNode.indent+=(nNode.hasNode?"":"") if (select_value==id){select_ed = " selected"}else{select_ed = "";} <%if MustChildFolder = "1" then%> if(nNode.hasNode){ str+="<option value=\"\">"+nNode.indent+this.DrawLink(nid)+"</option>" str+=this.DrawTree(nNode) } else { str+="<option value=\""+id+"\""+select_ed+">"+nNode.indent+this.DrawLink(nid)+"</option>" } <%else%> str+="<option value=\""+id+"\""+select_ed+">"+nNode.indent+this.DrawLink(nid)+"</option>" if(nNode.hasNode){ str+=this.DrawTree(nNode) } <%end if%> return str; } TreeView.prototype.DrawLine=function(nNode,tem){ for(var i=1;i<this.nodes.length;i++){ if(this.nodes[i].id==tem.pid){ nNode.indent=(this.nodes[i].lastNode?this.config.blank.txt:this.config.line.txt)+nNode.indent this.DrawLine(nNode,this.nodes[i]) } } } TreeView.prototype.DrawLink=function(nid){ var nNode=this.nodes[nid] return nNode.txt } TreeView.prototype.toString=function(){ var str="" for(var i=0;i<this.nodes.length;i++)this.ChkPro(this.nodes[i]) str+=this.DrawTree(this.root) return str } var dbtree=new TreeView('dbtree','main') dbtree.add(0,-1,'根目录'); <% dim select_sql select_sql = "Select " & db_id & "," & db_pid & "," & db_text & " from [" & db_table & "]" Set rs = Conn.Execute(select_sql) While rs.EOF =flase Thisid=rs(db_id) %> dbtree.add(<%=rs(db_id)%>,<%=rs(db_pid)%>,'<%=rs(db_text)%>');<% rs.MoveNext Wend rs.close Set rs=nothing conn.close Set conn=nothing %> document.write("<select name='<% = select_name %>'><option value=\"\">请选择</option>"+dbtree+"</select>");
网站推荐:
虎的笑话
虎的成语
虎的歇后语
在线小游戏
成语排行榜
歇后语排行榜
中华五千年
文革图片
转载本站内容,请务必保留原作者信息。
本站提供的内容部分是在网上搜集,如果侵犯了您的版权,请告之,我们会删除内容或加上您的信息。(
网站留言
、
站内搜索
)