通过ajax 读取xml,得到数据后,想建立一颗树。
树的结构:
+A
-B
-C
-D
-E
........
结构就是这样下来的
点击A后出现下面节点,B前一个空格 C前两个空格,依次类推下去。
那位大虾能给个例子学习一下 谢谢啦!
树的结构:
+A
-B
-C
-D
-E
........
结构就是这样下来的
点击A后出现下面节点,B前一个空格 C前两个空格,依次类推下去。
那位大虾能给个例子学习一下 谢谢啦!
解决方案 »
- 关于列表的问题
- string数组如何转化为string
- 大家写web程序都用什么工具,我居然用Tomcat+UltrEdit + jdk!!!!
- 如何在 Eclipse 中连接 MSSqlserver ? UP 有分!
- 显示下载地址连接的问题
- 我的用tomcat做服务器,没用连接池,能负载多少人在线啊?
- 关于JSP按钮设计的高级问题,请高手指点
- 【请问】如何用jsp画饼图,在论坛上搜索了半天也没找到满意的答案,分不够再开贴给,谢...
- 那里可以下载免费的、不用注册的用java applet做的treeview
- 求推荐一个html在线编辑器
- ajax 读取xml数据后 动态生成树
- 谁有struts开发的项目的构造设计文档?
第一个后面跟上一个
第二个跟二个,
依次类推
<script language="JavaScript">
var container = document.all["Tree"];
var root = new Root("root", "全部客户", "", "全部客户", CLOSED, NON_LOADED, container);
root.setEditable(false);
root.setRootVarName('root');
root.setTarget("document.all.ShowContent")
root.setTargetType("IFRAME");
root.setCSSClass("text");
root.setIconPath("images");
var recyclebin = root.addNode('recyclebin','客户1','showrecyclebin.action','客户1',CLOSED,LOADED);
var invaliddocbin = root.addNode('invaliddocbin','客户2','showinvaliddocbin.action','客户2',CLOSED,LOADED);
var invaliddocbin2 = root.addNode('invaliddocbin2','客户3','showinvaliddocbin.action','客户3',CLOSED,LOADED);
var fdewqeqjpx=root.addNode('fdewqeqjpx','客户4','','gfft',CLOSED,LOADED);
var datacollection1=fdewqeqjpx.addNode('datacollection1','1大类','./admin_login.jsp','1大类',CLOSED,LOADED);
var datacollection2=fdewqeqjpx.addNode('datacollection2','2大类','./admin_login1.jsp','2大类',CLOSED,LOADED);
var datacollection3=fdewqeqjpx.addNode('datacollection3','3大类','./admin_login.jsp','3大类',CLOSED,LOADED);
root.draw();
</script>
其实就是W3C和Dom
if(xmlHttp.readyState == 4){
if(xmlHttp.status == 200){
// alert(xmlHttp.responseText);
var xmlDoc = xmlHttp.responseXML.getElementsByTagName('item');
// alert(xmlDoc.length);
for(var i=0;i<xmlDoc.length;i++){
var aNode=xmlDoc.item(i);
var serviceids = aNode.getElementsByTagName( 'serviceid' );
var serviceid = serviceids.item(0).firstChild.nodeValue;
var servnams = aNode.getElementsByTagName( 'servnam' );
var servnam = servnams.item(0).firstChild.nodeValue;
var typs = aNode.getElementsByTagName( 'typ' );
var typ = typs.item(0).firstChild.nodeValue;
var isshows = aNode.getElementsByTagName( 'isshow' );
var isshow = isshows.item(0).firstChild.nodeValue;
var parentservices = aNode.getElementsByTagName( 'parentservice' );
var parentservice = parentservices.item(0).firstChild.nodeValue;
var entrtranses = aNode.getElementsByTagName( 'entrtrans' );
var entrtrans;
var enttem=entrtranses.item(0).firstChild;
if(enttem!=null)
entrtrans = entrtranses.item(0).firstChild.nodeValue;
else
entrtrans = "-1";
// alert(serviceid+":"+servnam+":"+typ+":"+isshow+":"+parentservice+":"+entrtrans);
var div1=document.createElement("div");
var a0=document.createElement("a");
a0.setAttribute("href","javascript:changeOne('"+serviceid+"');");
var a1=document.createElement("a");
a1.setAttribute("href","javascript:changeOne('"+serviceid+"');");
var a2=document.createElement("a");
a2.setAttribute("href","javascript:changeOne('"+serviceid+"');");
a2.className="divS";
var aText=document.createTextNode(servnam);
var aImg=document.createElement("img");
aImg.setAttribute("id",serviceid+"Img");
aImg.setAttribute("border","0");
aImg.setAttribute("align ","right");
var aImg0=document.createElement("img");
aImg0.setAttribute("id",serviceid+"Img0");
aImg0.setAttribute("border","0");
aImg0.setAttribute("align ","right");
if(typ=="1"){//没有下级(文件)
aImg.setAttribute("src","/Item/images/ftv2doc.gif");
if(i==xmlDoc.length-1){
div1.setAttribute("isend","yes");
aImg0.setAttribute("src","/Item/images/joinbottom.gif");
}else{
div1.setAttribute("isend","no");
aImg0.setAttribute("src","/Item/images/ftv2node.gif");
}
}else{//有下级(目录)
aImg.setAttribute("src","/Item/images/ftv2folderclosed.gif");
if(i==xmlDoc.length-1){
div1.setAttribute("isend","yes");
if(nextGrade==0){
div1.setAttribute("final","yes");
}else if(obj.getAttribute("final")=="yes"){
div1.setAttribute("final","yes");
}
aImg0.setAttribute("src","/Item/images/ftv2plastnode.gif");
}else{
div1.setAttribute("isend","no");
aImg0.setAttribute("src","/Item/images/ftv2pnode.gif");
}
}
var div2=document.createElement("div");
a0.appendChild(aImg0);
a1.appendChild(aImg);
a2.appendChild(aText);
a2.setAttribute("title",aText);
var aTable=document.createElement("table");
aTable.setAttribute("border","0,1px");
aTable.setAttribute("cellPadding","0");
aTable.setAttribute("cellSpacing","0");
var aTBody=document.createElement("tbody");
var aRow=document.createElement("tr");
var aCell0=document.createElement("td");
aCell0.setAttribute("valign","middle");
var aCell1=document.createElement("td");
aCell1.setAttribute("valign","middle");
var aCell2=document.createElement("td");
aCell2.setAttribute("valign","middle");
aCell0.appendChild(a0);
aCell1.appendChild(a1);
aCell2.appendChild(a2);
for(var j=0;j<nextGrade;j++){
var aCell=document.createElement("td");
aCell.setAttribute("valign","middle");
var aImage=document.createElement("img");
parentE=document.getElementById(parentservice);
if(parentE.final!="yes"){
if(parentE.isend=="yes"){
if(j==nextGrade-1){
aImage.setAttribute("src","/Item/images/dian.gif");
aCell.setAttribute("width","17");
}else{
aImage.setAttribute("src","/Item/images/ftv2vertline.gif");
}
}else{
aImage.setAttribute("src","/Item/images/ftv2vertline.gif");
}
}else{
aImage.setAttribute("src","/Item/images/dian.gif");
aCell.setAttribute("width","17");
}
aCell.appendChild(aImage);
aCell.appendChild(aImage);
aRow.appendChild(aCell);
}
aRow.appendChild(aCell0);
aRow.appendChild(aCell1);
aRow.appendChild(aCell2);
aTBody.appendChild(aRow);
aTable.appendChild(aTBody);
div1.appendChild(aTable);
这是JAVA里的一段代码:
private String createXML(ResultSet rs) throws SQLException, UnsupportedEncodingException{
StringBuffer xml=new StringBuffer("\r\n<items>\r\n");
while(rs.next()){
xml.append("<item>\r\n");
String serviceId=rs.getString(1);
xml.append("<serviceid>").append(serviceId).append("</serviceid>\r\n");
String serviceName=rs.getString(2);
xml.append("<servnam>").append(serviceName).append("</servnam>\r\n");
String type=rs.getString(3);
xml.append("<typ>").append(type).append("</typ>\r\n");
String isShow=rs.getString(4);
xml.append("<isshow>").append(isShow).append("</isshow>\r\n");
String parentService=rs.getString(5);
xml.append("<parentservice>").append(parentService).append("</parentservice>\r\n");
String entrTrans=null2String(rs.getString(6));
xml.append("<entrtrans>").append(entrTrans).append("</entrtrans>\r\n");
xml.append("</item>\r\n");
}
xml.append("</items>");
return xml.toString();
}
<head>
<style type="text/css">
.divS{
color:blue;
font-size:13px;
}
</style>
<style>
A:link,A:visited ,A:active {TEXT-DECORATION: none}
A:hover {text-decoration : none; position : relative; top : 1px; left : 1px}
a:link{
text-decoration: none;
}
a:hover{
color:red; }
a:visited {
color:red;
} </style><meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>Insert title here</title>
<script type="text/javascript">
function newXMLHttpRequest() {//获取请求对象 var xmlreq = false;
if (window.XMLHttpRequest) {
xmlreq = new XMLHttpRequest();
} else if (window.ActiveXObject) {
try {
xmlreq = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e1) {
try {
xmlreq = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e2) {
}
}
}
return xmlreq;
}
function send(obj){
var xmlHttp=newXMLHttpRequest();
var url="/Item/MenuServlet";
var nextGrade=parseInt(obj.getAttribute("grade"))+1;
if(nextGrade!=0){
url+="?id="+obj.id;
}
//var url="/Item/jsp/products.jsp";
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=function(){
if(xmlHttp.readyState == 4){
if(xmlHttp.status == 200){
// alert(xmlHttp.responseText);
var xmlDoc = xmlHttp.responseXML.getElementsByTagName('item');
// alert(xmlDoc.length);
for(var i=0;i<xmlDoc.length;i++){
var aNode=xmlDoc.item(i);
var serviceids = aNode.getElementsByTagName( 'serviceid' );
var serviceid = serviceids.item(0).firstChild.nodeValue;
var servnams = aNode.getElementsByTagName( 'servnam' );
var servnam = servnams.item(0).firstChild.nodeValue;
var typs = aNode.getElementsByTagName( 'typ' );
var typ = typs.item(0).firstChild.nodeValue;
var isshows = aNode.getElementsByTagName( 'isshow' );
var isshow = isshows.item(0).firstChild.nodeValue;
var parentservices = aNode.getElementsByTagName( 'parentservice' );
var parentservice = parentservices.item(0).firstChild.nodeValue;
var entrtranses = aNode.getElementsByTagName( 'entrtrans' );
var entrtrans;
var enttem=entrtranses.item(0).firstChild;
if(enttem!=null)
entrtrans = entrtranses.item(0).firstChild.nodeValue;
else
entrtrans = "-1";
// alert(serviceid+":"+servnam+":"+typ+":"+isshow+":"+parentservice+":"+entrtrans);
var div1=document.createElement("div");
var a0=document.createElement("a");
a0.setAttribute("href","javascript:changeOne('"+serviceid+"');");
var a1=document.createElement("a");
a1.setAttribute("href","javascript:changeOne('"+serviceid+"');");
var a2=document.createElement("a");
a2.setAttribute("href","javascript:changeOne('"+serviceid+"');");
a2.className="divS";
var aText=document.createTextNode(servnam);
var aImg=document.createElement("img");
aImg.setAttribute("id",serviceid+"Img");
aImg.setAttribute("border","0");
aImg.setAttribute("align ","right");
var aImg0=document.createElement("img");
aImg0.setAttribute("id",serviceid+"Img0");
aImg0.setAttribute("border","0");
aImg0.setAttribute("align ","right");
if(typ=="1"){//没有下级(文件)
aImg.setAttribute("src","/Item/images/ftv2doc.gif");
if(i==xmlDoc.length-1){
div1.setAttribute("isend","yes");
aImg0.setAttribute("src","/Item/images/joinbottom.gif");
}else{
div1.setAttribute("isend","no");
aImg0.setAttribute("src","/Item/images/ftv2node.gif");
}
}else{//有下级(目录)
aImg.setAttribute("src","/Item/images/ftv2folderclosed.gif");
if(i==xmlDoc.length-1){
div1.setAttribute("isend","yes");
if(nextGrade==0){
div1.setAttribute("final","yes");
}else if(obj.getAttribute("final")=="yes"){
div1.setAttribute("final","yes");
}
aImg0.setAttribute("src","/Item/images/ftv2plastnode.gif");
}else{
div1.setAttribute("isend","no");
aImg0.setAttribute("src","/Item/images/ftv2pnode.gif");
}
}
var div2=document.createElement("div");
a0.appendChild(aImg0);
a1.appendChild(aImg);
a2.appendChild(aText);
a2.setAttribute("title",aText);
var aTable=document.createElement("table");
aTable.setAttribute("border","0,1px");
aTable.setAttribute("cellPadding","0");
aTable.setAttribute("cellSpacing","0");
var aTBody=document.createElement("tbody");
var aRow=document.createElement("tr");
var aCell0=document.createElement("td");
aCell0.setAttribute("valign","middle");
var aCell1=document.createElement("td");
aCell1.setAttribute("valign","middle");
var aCell2=document.createElement("td");
aCell2.setAttribute("valign","middle");
aCell0.appendChild(a0);
aCell1.appendChild(a1);
aCell2.appendChild(a2);
for(var j=0;j<nextGrade;j++){
var aCell=document.createElement("td");
aCell.setAttribute("valign","middle");
var aImage=document.createElement("img");
parentE=document.getElementById(parentservice);
if(parentE.final!="yes"){
if(parentE.isend=="yes"){
if(j==nextGrade-1){
aImage.setAttribute("src","/Item/images/dian.gif");
aCell.setAttribute("width","17");
}else{
aImage.setAttribute("src","/Item/images/ftv2vertline.gif");
}
}else{
aImage.setAttribute("src","/Item/images/ftv2vertline.gif");
}
}else{
aImage.setAttribute("src","/Item/images/dian.gif");
aCell.setAttribute("width","17");
}
aCell.appendChild(aImage);
aCell.appendChild(aImage);
aRow.appendChild(aCell);
}
aRow.appendChild(aCell0);
aRow.appendChild(aCell1);
aRow.appendChild(aCell2);
aTBody.appendChild(aRow);
aTable.appendChild(aTBody);
div1.appendChild(aTable);
div1.setAttribute("id",serviceid);
div1.setAttribute("names",servnam);
div1.setAttribute("typ",typ);
div1.setAttribute("parentservice",parentservice);
div1.setAttribute("name",parentservice);
div1.setAttribute("entrtrans",entrtrans);
div1.setAttribute("isopen","no");
div1.setAttribute("grade",""+nextGrade);
obj.appendChild(div1);
}
alert(obj.innerHTML);
}
}
}
xmlHttp.send(null);
}
function init(){
// send(document.getElementById("all1"));
var map=new Map();
map.put("1","111");
//alert(map.get("2"));
}
var div1=document.getElementById(obj);
var isEnd=div1.getAttribute("isend");
if(div1.typ=="0"){//有下级
if(div1.isopen=="no"){
div1.isopen="yes";
document.getElementById(obj+"Img").src="/Item/images/ftv2folderopen.gif";
if(isEnd=="yes"){
document.getElementById(obj+"Img0").src="/Item/images/ftv2mlastnode.gif";
}else{
document.getElementById(obj+"Img0").src="/Item/images/ftv2mnode.gif";
}
send(div1);
}else{
div1.isopen="no";
document.getElementById(obj+"Img").src="/Item/images/ftv2folderclosed.gif";
if(isEnd=="yes"){
document.getElementById(obj+"Img0").src="/Item/images/ftv2plastnode.gif";
}else{
document.getElementById(obj+"Img0").src="/Item/images/ftv2pnode.gif";
}
var nodes=div1.children;
var arr=new Array();
for(var k=nodes.length-1;k>=0;k--){
if(div1.children.item(k).parentservice==obj)
div1.removeChild(div1.children.item(k));
}
}
}else{//没有下级
}
}
function Map(){
this.get=getElem;
this.put=setElem;
this.length=size;
this.del=deleteElem;
}
Map.prototype.allElem=new Array();
function size(){
return this.allElem.length;
}
function getElem(key){
for(var i=0;i<this.length();i++){
var arr=this.allElem[i];
if(arr[0]==key){
return arr[1];
}
}
return null;
}
function deleteElem(key){
for(var i=0;i<this.length();i++){
var arr=this.allElem[i];
if(arr[0]==key){
return arr[1];
}
}
}
function setElem(key,value){
var arr=new Array();
arr[0]=key;
arr[1]=value;
this.allElem[this.allElem.length]=arr;
}
</script>
</head>
<body onload="init()">
<div id="all1" grade="-1" class="divS">
<table cellPadding="0" border="0" cellSpacing="0">
<tbody>
<tr><td><img src="/Item/images/ftv2folderopen.gif"/></td><td><td valign="middle"><div style="color:blue">功能模块</div></td></tr>
</tbody>
</table>
</div></body>
</html>
还有图片:
生成树// Node object
function Node(id, pid, name, url, title, target, icon, iconOpen, open) {
this.id = id;
this.pid = pid;
this.name = name;
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;
};// Tree object
function dTree(objName) {
this.config = {
target : null,
folderLinks : true,
useSelection : true,
useCookies : true,
useLines : true,
useIcons : true,
useStatusText : false,
closeSameLevel : false,
inOrder : false
}
this.icon = {
root : '../images/img/base.gif',
folder : '../images/img/folder.gif',
folderOpen : '../images/img/folderopen.gif',
node : '../images/img/page.gif',
empty : '../images/img/empty.gif',
line : '../images/img/line.gif',
join : '../images/img/join.gif',
joinBottom : '../images/img/joinbottom.gif',
plus : '../images/img/plus.gif',
plusBottom : '../images/img/plusbottom.gif',
minus : '../images/img/minus.gif',
minusBottom : '../images/img/minusbottom.gif',
nlPlus : '../images/img/nolines_plus.gif',
nlMinus : '../images/img/nolines_minus.gif'
};
this.obj = objName;
this.aNodes = [];
this.aIndent = [];
this.root = new Node(-1);
this.selectedNode = null;
this.selectedFound = false;
this.completed = false;
};// Adds a new node to the node array
dTree.prototype.add = function(id, pid, name, url, title, target, icon, iconOpen, open) {
this.aNodes[this.aNodes.length] = new Node(id, pid, name, url, title, target, icon, iconOpen, open);
};// Open/close all nodes
dTree.prototype.openAll = function() {
this.oAll(true);
};
dTree.prototype.closeAll = function() {
this.oAll(false);
};// Outputs the tree to the page
dTree.prototype.toString = function() {
var str = '<div class="dtree">\n';
if (document.getElementById) {
if (this.config.useCookies) this.selectedNode = this.getSelected();
str += this.addNode(this.root);
} else str += 'Browser not supported.';
str += '</div>';
if (!this.selectedFound) this.selectedNode = null;
this.completed = true;
return str;
};// Creates the tree structure
dTree.prototype.addNode = function(pNode) {
var str = '';
var n=0;
if (this.config.inOrder) n = pNode._ai;
for (n; n<this.aNodes.length; n++) {
if (this.aNodes[n].pid == pNode.id) {
var cn = this.aNodes[n];
cn._p = pNode;
cn._ai = n;
this.setCS(cn);
if (!cn.target && this.config.target) cn.target = this.config.target;
if (cn._hc && !cn._io && this.config.useCookies) cn._io = this.isOpen(cn.id);
if (!this.config.folderLinks && cn._hc) cn.url = null;
if (this.config.useSelection && cn.id == this.selectedNode && !this.selectedFound) {
cn._is = true;
this.selectedNode = n;
this.selectedFound = true;
}
str += this.node(cn, n);
if (cn._ls) break;
}
}
return str;
};// Creates the node icon, url and text
dTree.prototype.node = function(node, nodeId) {
var str = '<div class="dTreeNode">' + this.indent(node, nodeId);
if (this.config.useIcons) {
if (!node.icon) node.icon = (this.root.id == node.pid) ? this.icon.root : ((node._hc) ? this.icon.folder : this.icon.node);
if (!node.iconOpen) node.iconOpen = (node._hc) ? this.icon.folderOpen : this.icon.node;
if (this.root.id == node.pid) {
node.icon = this.icon.root;
node.iconOpen = this.icon.root;
}
str += '<img id="i' + this.obj + nodeId + '" src="' + ((node._io) ? node.iconOpen : node.icon) + '" alt="" />';
}
str += '<a id="'+node.id+'" href="javascript:operate(\'edit\',\'' + node.id + '\',\'' + node.pid + '\');" class="node" target=\"mainFrame\">';
// str += '<a href="../org/edit.do?id='+node.id+'" class="node" target=\"mainFrame\">';
str += node.name;
str += '</a>';
// if (node.url || ((!this.config.folderLinks || !node.url) && node._hc)) str += '</a>';
str += '</div>';
if (node._hc) {
str += '<div id="d' + this.obj + nodeId + '" class="clip" style="display:' + ((this.root.id == node.pid || node._io) ? 'block' : 'none') + ';">';
str += this.addNode(node);
str += '</div>';
}
this.aIndent.pop();
return str;
};// Adds the empty and line icons
dTree.prototype.indent = function(node, nodeId) {
var str = '';
if (this.root.id != node.pid) {
for (var n=0; n<this.aIndent.length; n++)
str += '<img border="0" src="' + ( (this.aIndent[n] == 1 && this.config.useLines) ? this.icon.line : this.icon.empty ) + '" alt="" />';
(node._ls) ? this.aIndent.push(0) : this.aIndent.push(1);
if (node._hc) {
str += '<a href="javascript: ' + this.obj + '.o(' + nodeId + ');"><img border="0" id="j' + this.obj + nodeId + '" src="';
if (!this.config.useLines) str += (node._io) ? this.icon.nlMinus : this.icon.nlPlus;
else str += ( (node._io) ? ((node._ls && this.config.useLines) ? this.icon.minusBottom : this.icon.minus) : ((node._ls && this.config.useLines) ? this.icon.plusBottom : this.icon.plus ) );
str += '" alt="" /></a>';
} else str += '<img border="0" src="' + ( (this.config.useLines) ? ((node._ls) ? this.icon.joinBottom : this.icon.join ) : this.icon.empty) + '" alt="" />';
}
return str;
};// Checks if a node has any children and if it is the last sibling
dTree.prototype.setCS = function(node) {
var lastId;
for (var n=0; n<this.aNodes.length; n++) {
if (this.aNodes[n].pid == node.id) node._hc = true;
if (this.aNodes[n].pid == node.pid) lastId = this.aNodes[n].id;
}
if (lastId==node.id) node._ls = true;
};// Returns the selected node
dTree.prototype.getSelected = function() {
var sn = this.getCookie('cs' + this.obj);
return (sn) ? sn : null;
};// Highlights the selected node
dTree.prototype.s = function(id) {
if (!this.config.useSelection) return;
var cn = this.aNodes[id];
if (cn._hc && !this.config.folderLinks) return;
if (this.selectedNode != id) {
if (this.selectedNode || this.selectedNode==0) {
eOld = document.getElementById("s" + this.obj + this.selectedNode);
eOld.className = "node";
}
eNew = document.getElementById("s" + this.obj + id);
eNew.className = "nodeSel";
this.selectedNode = id;
if (this.config.useCookies) this.setCookie('cs' + this.obj, cn.id);
}
};// Toggle Open or close
dTree.prototype.o = function(id) {
var cn = this.aNodes[id];
this.nodeStatus(!cn._io, id, cn._ls);
cn._io = !cn._io;
if (this.config.closeSameLevel) this.closeLevel(cn);
if (this.config.useCookies) this.updateCookie();
};
// checkbox selecteddTree.prototype.p = function(obj) {
if(obj.checked) {
for(var i=0; i<document.pageform.checkname.length; i++) {
if(document.pageform.checkname[i].id==obj.value) {
document.pageform.checkname[i].checked=true;
}
}
}else {
for(var i=0; i<document.pageform.checkname.length; i++) {
if(document.pageform.checkname[i].value==obj.id) {
document.pageform.checkname[i].checked=false;
}
}
for(var i=0; i<document.pageform.checkname.length; i++) {
if(document.pageform.checkname[i].id==obj.value) {
document.pageform.checkname[i].checked=false;
}
}
}
};// Open or close all nodes
dTree.prototype.oAll = function(status) {
for (var n=0; n<this.aNodes.length; n++) {
if (this.aNodes[n]._hc && this.aNodes[n].pid != this.root.id) {
this.nodeStatus(status, n, this.aNodes[n]._ls)
this.aNodes[n]._io = status;
}
}
if (this.config.useCookies) this.updateCookie();
};
dTree.prototype.openTo = function(nId, bSelect, bFirst) {
if (!bFirst) {
for (var n=0; n<this.aNodes.length; n++) {
if (this.aNodes[n].id == nId) {
nId=n;
break;
}
}
}
var cn=this.aNodes[nId];
if (cn.pid==this.root.id || !cn._p) return;
cn._io = true;
cn._is = bSelect;
if (this.completed && cn._hc) this.nodeStatus(true, cn._ai, cn._ls);
if (this.completed && bSelect) this.s(cn._ai);
else if (bSelect) this._sn=cn._ai;
this.openTo(cn._p._ai, false, true);
};// Closes all nodes on the same level as certain node
dTree.prototype.closeLevel = function(node) {
for (var n=0; n<this.aNodes.length; n++) {
if (this.aNodes[n].pid == node.pid && this.aNodes[n].id != node.id && this.aNodes[n]._hc) {
this.nodeStatus(false, n, this.aNodes[n]._ls);
this.aNodes[n]._io = false;
this.closeAllChildren(this.aNodes[n]);
}
}
}// Closes all children of a node
dTree.prototype.closeAllChildren = function(node) {
for (var n=0; n<this.aNodes.length; n++) {
if (this.aNodes[n].pid == node.id && this.aNodes[n]._hc) {
if (this.aNodes[n]._io) this.nodeStatus(false, n, this.aNodes[n]._ls);
this.aNodes[n]._io = false;
this.closeAllChildren(this.aNodes[n]);
}
}
}// Change the status of a node(open or closed)
dTree.prototype.nodeStatus = function(status, id, bottom) {
eDiv = document.getElementById('d' + this.obj + id);
eJoin = document.getElementById('j' + this.obj + id);
if (this.config.useIcons) {
eIcon = document.getElementById('i' + this.obj + id);
eIcon.src = (status) ? this.aNodes[id].iconOpen : this.aNodes[id].icon;
}
eJoin.src = (this.config.useLines)?
((status)?((bottom)?this.icon.minusBottom:this.icon.minus):((bottom)?this.icon.plusBottom:this.icon.plus)):
((status)?this.icon.nlMinus:this.icon.nlPlus);
eDiv.style.display = (status) ? 'block': 'none';
};
// [Cookie] Clears a cookie
dTree.prototype.clearCookie = function() {
var now = new Date();
var yesterday = new Date(now.getTime() - 1000 * 60 * 60 * 24);
this.setCookie('co'+this.obj, 'cookieValue', yesterday);
this.setCookie('cs'+this.obj, 'cookieValue', yesterday);
};// [Cookie] Sets value in a cookie
dTree.prototype.setCookie = function(cookieName, cookieValue, expires, path, domain, secure) {
document.cookie =
escape(cookieName) + '=' + escape(cookieValue)
+ (expires ? '; expires=' + expires.toGMTString() : '')
+ (path ? '; path=' + path : '')
+ (domain ? '; domain=' + domain : '')
+ (secure ? '; secure' : '');
};// [Cookie] Gets a value from a cookie
dTree.prototype.getCookie = function(cookieName) {
var cookieValue = '';
var posName = document.cookie.indexOf(escape(cookieName) + '=');
if (posName != -1) {
var posValue = posName + (escape(cookieName) + '=').length;
var endPos = document.cookie.indexOf(';', posValue);
if (endPos != -1) cookieValue = unescape(document.cookie.substring(posValue, endPos));
else cookieValue = unescape(document.cookie.substring(posValue));
}
return (cookieValue);
};// [Cookie] Returns ids of open nodes as a string
dTree.prototype.updateCookie = function() {
var str = '';
for (var n=0; n<this.aNodes.length; n++) {
if (this.aNodes[n]._io && this.aNodes[n].pid != this.root.id) {
if (str) str += '.';
str += this.aNodes[n].id;
}
}
this.setCookie('co' + this.obj, str);
};// [Cookie] Checks if a node id is in a cookie
dTree.prototype.isOpen = function(id) {
var aOpen = this.getCookie('co' + this.obj).split('.');
for (var n=0; n<aOpen.length; n++)
if (aOpen[n] == id) return true;
return false;
};// If Push and pop is not implemented by the browser
if (!Array.prototype.push) {
Array.prototype.push = function array_push() {
for(var i=0;i<arguments.length;i++)
this[this.length]=arguments[i];
return this.length;
}
};
if (!Array.prototype.pop) {
Array.prototype.pop = function array_pop() {
lastElement = this[this.length-1];
this.length = Math.max(this.length-1,0);
return lastElement;
}
};jsp页:
<script type="text/javascript">
<!--
d = new dTree('d');
for(var i=0; i<document.leftform.id.length; i++) {
if(document.leftform.node_level[i].value.length==2){
d.add(00,-1,'ICS系统');
}
d.add(document.leftform.id[i].value,document.leftform.node_level[i].value,document.leftform.node_name[i].value,document.leftform.node_type[i].value);
}
document.write(d);
//-->
</script>function RDFile(){
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
if(!xmlDoc.load("C:\\test.xml")){
$("result").innerHTML="没有记录!";
return;
}
var xpair=xmlDoc.getElementsByTagName("pair");
if(xpair.length==0){
$("result").innerHTML="没有记录!";
return;
}
$("result").innerHTML="";
for(var i=0;i<xpair.length;i++) {
$("result").innerHTML+="<div id=\"a2\" onclick=\"fnGetTags("+i+")\">"+"收款人:"+xpair[i].firstChild.text+"</div>"+"<p />";
}
return;
} 这些是我做项目时用的的,你改改就能用了
读数据