在网上发现了一个老外写的JS无限级数。
效果如图:

下载:https://files.cnblogs.com/zjfree/jsTree.zip
代码写的很赞,准备好好学习一下。
循环UL下的所有LI
for (var li = ul.lastChild; li; li = li.previousSibling)
if (li.nodeName == "LI") {
//处理UL下的所有LI
}
获取事件触发者
img.onclick = function(e) {
e = e || window.event;
var t = e.target || e.srcElement;
//t为事件触发者
}
在LI中最前面添加元素
li.insertBefore(img, li.firstChild);
获取最近的父级LI
while (li && li.nodeName != "LI") li = li.parentNode;
添加或删除class
span.className += ", newClass ,";
span.className = span.className.replace(", newClass ,", "");
创建类,使用JSON格式定义
function Tree(elId) {
this.name = 'aaa';
this.elem = null;
this.id = elId;
this.opt = {
icons:['aaa','bbb'],
getIcon:function(){
//获取图标
}
};
this.alert = function(msg){
alert(msg);
};
}
var t = new Tree('t');
t.alert('ssss');