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

Javascript
javascript表单之间的数据传递
当层遇到select下拉框时的解决方法
showModalDialog和showModelessDialog使用心得
JavaScript技巧:让网页自动穿上外套
一个非常强大完整的web表单验证程序
JavaScript实用技巧集锦
js控制excel打印完美解决方案
使用Javascript制作声音按钮
利用 PHP 将 HTML 转化为 WML
Javascript经典正则表达式
新闻内页-JS分页
鼠标划过时整行变色
用 或 || 来兼容FireFox
JS代码的格式化和压缩
动态加载iframe
html下载本地
强制设为首页代码
超强图片数量上传无限制
document 和 document.all 分别什么时候用
javascript 动态添加表格行

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


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