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

Javascript
javascript实例教程(15) 日期函数
javascript实例教程(17) 使用字符串函数
javascript实例教程(18) 数组
javascript实例教程(19) 使用HoTMetal(1)
javascript实例教程(19) 使用HoTMetal(2)
javascript实例教程(19) 使用HoTMetal(3)
javascript实例教程(19) 使用HoTMetal(4)
javascript使图片加载进度实时显示
代码前置时页面输出脚本的要注意的问题|
javascript网页中显示硬盘内容
JS实现仿新浪信息提示效果
Js 按照MVC模式制作自定义控件
滑动展开/收缩广告代码实例效果
JS实现的滑动展开与折叠效果
时钟广告跳转状态栏等JS代码
一个以Javascript+xml的树型列表
target 属性怎么用 JS 来控制?
一组常用的弹出窗口用法总结
冒泡算法的三种JavaScript表示
网页最简短的拖动对象代码实例演示

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


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