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

Javascript
Javascript实例教程(17) 使用Javascript的数学函数
JavaScript 小技巧(第六集)
Javascript实例教程(16) 日期函数
javascript中如何实现浏览器上的右键菜单
Javascript实例教程(21) OLE Automation(7)
JavaScript 小技巧(第二集)
Javascript设计网页中的下拉菜单
用JavaScript使链接按钮不断变化
如何制作浮动广告
JavaScript[对象.属性]集锦之一
将金额小写转化成汉字大写的实现过程
Javascript制作浮动的工具条
JavaScript[对象.属性]集锦之二
JavaScript 小技巧(第五集)
JavaScript 小技巧(第七集)
完美解决一个事件激活多个函数
JavaScript入门学习之一
在客户端把表格行变成列,列变成行并保持TD的属性不丢失
用 Javascript 实现的“Dual listbox”(双向选择器)
我与Javascript 随笔(一)(献给所有爱好Javascript的朋友)

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-08-10   浏览: 238 ::
收藏到网摘: 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;
}