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

Javascript
js 创建一个浮动div的代码
javascript下利用数组缓存正则表达式的实现方法
javascript 最常用的10个自定义函数[推荐]
jQuery 常见开发使用技巧总结
十分钟打造AutoComplete自动完成效果代码
JavaScript 入门基础知识 想学习js的朋友可以参考下
javascript 清空form表单中某种元素的值
javascript 格式化时间日期函数代码脚本之家修正版
javascript dom操作之cloneNode文本节点克隆使用技巧
jQuery 动态酷效果实现总结
jQuery中的常用事件总结
用Jquery实现可编辑表格并用AJAX提交到服务器修改数据
javascript+css 网页每次加载不同样式的实现方法
向大师们学习Javascript(视频与PPT)
js 实现无干扰阴影效果 简单好用(附文件下载)
JavaScript 拾漏补遗
IE6 弹出Iframe层中的文本框“经常”无法获得输入焦点
jQuery的强大选择器小结
jquery $(document).ready() 与window.onload的区别
javascript 动态调整图片尺寸实现代码

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


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