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

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 zhangyijun 的 blog

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;
}

本文关键:javascript
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top