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

Javascript
网页常用小技巧—javascript篇
中文的版用javascript实现超酷的“网页时钟”
60秒倒计时的一个小javascript
一步一步教你用JS和INF编辑注册表
仿Office 2003的工具条
javascript加密解密终级指南
在网页里做类似window右键的弹出式菜单
几行代码轻松搞定网页的简繁转换
利用Yahoo! Search API开发自已的搜索引擎-javascript版
服务器控件中js脚本注册方法
一行代码生成Google SiteMap
用javascript连接access数据库的方法
javascript+xml实现二级下拉菜单,不会被任何标签或元素遮住
javascript的IE和Firefox兼容性汇编
TreeView节点互斥,autopostback=false的方法
一个解析URL及图片地址的JS函数
javascript模拟ACDSEE简单功能
实现textarea内字符串选择查询替换功能
javascript Web页面内容导出到Word、Excel
在客户端设置cooke和获取cooke的函数

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


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