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

Javascript
网页中的图片的处理方法与代码
用javascript实现jquery的document.ready功能的实现代码
Exitjs获取DataView中图片文件名
javascript 加入收藏、设为首页(IE,firefox兼容脚本之家版)
isArray()函数(JavaScript中对象类型判断的几种方法)
Javascript 二维数组
js setattribute批量设置css样式
Javascript 复制数组实现代码
extJs 文本框后面加上说明文字+下拉列表选中值后触发事件
JavaScript 闭包在封装函数时的简单分析
javascript showModalDialog 多层模态窗口实现页面提交及刷新的代码
JavaScript 字符串操作的几种常见方法
javascript &&和||运算法的另类使用技巧
[原创]javascript代码在ie8里报错 document.getElementById(...) 为空或不是对象的解决方法
js鼠标移动在title中显示图片的效果代码
JavaScript Alert通用美化类
javascript 新闻列表排序简单封装
Javascript 构造函数,公有,私有特权和静态成员定义方法
javascript 设置某DIV区域内的checkbox复选框
document.body.scrollTop 值总为0的解决方法 比较常见的标准问题

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


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