繁体中文
设为首页
加入收藏
当前位置:程序开发首页 >> JavaScript >> 关于javascript树形结构的编写问题

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

2005-01-09 20:48:33  作者:zhangyijun  来源:互联网  浏览次数:70  文字大小:【】【】【
简介: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(...

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;

}

责任编辑:admin
相关文章