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

Javascript
JS教程:浅谈ECMAScript自动插入分号
JavaScript教程:几种比较熟悉的编程习惯
JS实例:登陆失败后跳出框架打开
webdesignledger推选的2009年度最佳jQuery插件
javaScript教程:以实例方式学习call函数
JS教程:词法作用域和闭包
表单验证中时间起止 如何做到递归处理
JS实例教程:当心JavaScript代码陷阱
Firebug技巧:脚本调试,选项卡和CSS调试
学习javascript:牛人的讲座视频和PPT
Clearbox 3:很酷的仿Lightbox脚本
JavaScript教程:详细解析网页图片预览效果
JS代码实例:实现随机加载不同的CSS样式
国人开发的比较优秀的js框架:como js
Webjx收集10个最常用Ajax技术的实例教程
JavaScript教程:优化次数过多的循环
出色的jQuery导航菜单的14个英文教程
JS教程:学习笔记之JS类
JS教程:详细讲解JS节点知识
COM中获取JavaScript数组大小的代码

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


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