当前位置: 首页 > 图文教程 > 网络编程 > Javascript > 关于javascript树形结构的编写问题

Javascript
网页对联广告代码效果大全
限制图片上传长宽的javascript代码
用javascript绘图—JS2D函数集
使主页呈现“飞舞”特效
用javascript实现浏览器地震效果
图片下拉选择器的制作
用JS将网页窗口由小变大
图片控制的渐变色文字
连续滚动的制作
制作仿“QQ秀”的虚拟形象
PHP与javascript对多项选择的处理
用JavaScrpt实现文件夹轻松加密
初学javascript之cookie篇(译)
javascript学习:基础继承机制
一个很通用的javascript的下拉菜单
javascript中的数组应用的一点发现
javascript表单之间的数据传递
一个简单的javascript菜单
预装载以及javascript Image()对象
网页软键盘,有效的防止监测键盘的木马软件

Javascript 中的 关于javascript树形结构的编写问题


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-08-10   浏览: 317 ::
收藏到网摘: n/a

function branch(id, text){
this.id = id;
this.text = text;
this.write = writeBranch;
this.add = addLeaf;
this.leaves = new Array();
this.getid=getid;
}
function getid(){return this.id;}

function addLeaf(leaf){
this.leaves[this.leaves.length] = leaf;
}

function writeBranch(){
var branchString =
'< span class="branch" ' + onClick="showBranch(this.getid())"';

//编译的时候出现了this.getid()必须要赋予一个变量的问题,也就是左值问题

求教!!!!!!!!
branchString += '>< img src="plus.gif" id="I' + this.id + '">' + this.text;
branchString += '< /span>';
branchString += '< span class="leaf" id="';
branchString += this.id + '">';
var numLeaves = this.leaves.length;
for (var j=0;j< numLeaves;j++) branchString += this.leaves[j].write();
branchString += '< /span>';
return branchString;
}