⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tree.js

📁 有关java的一个简单树
💻 JS
字号:
var appPath;
var imgPath = appPath + '/common/images/';
var imgBlank = imgPath + 'empty.gif';
var imgFolderClose = imgPath + 'folder_close.gif';
var imgFolderOpen = imgPath + 'folder_open.gif';
var imgText = imgPath + 'text_node.gif';

function Node(aId, aText){
	this.nodeId = aId;
	this.isOpen = false;
	this.nodeText = aText;
	this.link = '#';
	//this.title = ''; 其它属性
	//this.parentNode = null;
	this.childNodes = new Array();
	this.childCount = 0;
}

Node.prototype.addChild = function(aChildNode){
	//aChildNode.parentNode = this;
	this.childNodes[this.childCount++] = aChildNode;
}

function dispNode(aNode){

	if (aNode.childCount > 0){
		imgNode = aNode.isOpen ? imgFolderClose : imgFolderOpen;
		document.write('<img name="' + aNode.nodeId + '" style="cursor:hand" onclick="expand(this)" src="' + imgNode + '">' + aNode.nodeText);

	} else
		document.write('<img src="' + imgText + '"><a href="' + aNode.link + '">' + aNode.nodeText + '</a>');
}

function expand(obj){
	var divId = 'div' + obj.name;
	var divObj = document.getElementById(divId);

	if (divObj) with (divObj){
		if (style.display == 'none'){
			obj.src = imgFolderOpen;
			style.display = 'block';
		} else {
			obj.src = imgFolderClose;
			style.display = 'none';
		}
	}
}

function makeTree(aNode, aLevel){

	if (aLevel == 0) dispNode(aNode);

	document.write('<div id="div' + aNode.nodeId + '" style="display:block">');
	var tmpNode;
	var imgNode;
	for (var i=0; i < aNode.childCount; i++){
		tmpNode = aNode.childNodes[i];

		for (var j=0; j <= aLevel; j++)
			document.write('<img src="' + imgBlank + '">');

		dispNode(tmpNode);
		document.write('<br>');

		if (tmpNode.childCount > 0) makeTree(tmpNode, aLevel+1);
	}
	document.write('</div>');
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -