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

Javascript
11款基于Javascript的文件管理器
5款Javascript颜色选择器
JavaScript 对话框和状态栏使用说明
状态栏 时间显示效果 数字钟
在图片上单击获取图片原始大小
禁止在图片上使用右键
javascript 操作Word和Excel的实现代码
几个javascript操作word的参考代码
innerhtml用法 innertext用法 以及innerHTML与innertext的区别
解决表单中第一个非隐藏的元素获得焦点的一个方案
解决jquery .ajax 在IE下卡死问题的解决方法
javascript 实现划词标记划词搜索功能
用Greasemonkey 脚本收藏网站会员信息到本地
javascript 关于# 和 void的区别分析
DIV+CSS+JS 变灰弹出层
Ajax+Json 级联菜单实现代码
javascript 读取XML数据,在页面中展现、编辑、保存的实现
html 锁定页面(js遮罩层弹出div效果)
基于jQuery的日期选择控件
javascript获得CheckBoxList选中的数量

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


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