为何把这段JS代码放入ASPX中,显示不出来。应该从配置XML读取显示一个树。XMLFile2.xml如下:
<?xml version="1.0" encoding="utf-8" ?>
<root>
<node id="n1">
<name>我的电脑</name>
<icon>images/tree_icon_computer.gif</icon>
<explain>显示连接到此计算机的驱动器和硬件</explain>
</node>
<node id="2" parentid="n1">
<name>硬盘驱动器 (C:)</name>
<icon>images/tree_icon_driver.gif</icon>
</node>
<node id="3">
<name>网上邻居</name>
<icon>images/tree_icon_net.gif</icon>
<explain>显示到网站,网络计算机和FTP站点的快捷方式</explain>
</node>
</root>-----------------------------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8" ?>
<root>
<node id="n1">
<name>我的电脑</name>
<icon>images/tree_icon_computer.gif</icon>
<explain>显示连接到此计算机的驱动器和硬件</explain>
</node>
<node id="2" parentid="n1">
<name>硬盘驱动器 (C:)</name>
<icon>images/tree_icon_driver.gif</icon>
</node>
<node id="3">
<name>网上邻居</name>
<icon>images/tree_icon_net.gif</icon>
<explain>显示到网站,网络计算机和FTP站点的快捷方式</explain>
</node>
</root>-----------------------------------------------------------------------------------------
解决方案 »
- <a href="<%#Eval("url")%>">点击查看</a>路径问题
- |zyciis| 200分 如何用ASP.NET AJAX 中的UpdatePanel做像QQ空间的提示:数据正在提交(向服务器发送处理) 数据正在更新(读取服务器信息)
- 多图片上传的问题?
- 关于ASP.NET中的Table控件
- 跪求这样一个javascript函数(相应回车事件 ,当按钮在单行编辑控件上回车时,回车事件被转译成tab事件)急 猴急!
- .net response.write 位置控制
- 怎样改变DataGrid编辑状态下,单元格的大小!!!高手帮忙哈
- 快来帮帮我啊,!
- 请问哪里有Freetextbox的源码
- 发布到服务器后,日期参数格式发生了变化
- 要用JAVASCRIPT根据XML生成一个tree,如何写?
- 程序如何编写才能有效减少cpu占有率
// JScript File
function xmlTree(name) {
this.name = name; this.xmlFile = 'XMLFile2.xml';
this.iconPath = 'images/'
this.iconFolder = 'tree_icon_folder.gif';
this.iconFile = 'tree_icon_file.gif';
this.iconOpen = 'tree_arrow_open.gif';
this.iconOver = 'tree_arrow_over.gif';
this.iconClose = 'tree_arrow_close.gif';
this.mode = 0;
this.html = '';
this.prevTip = null;
this.prevSelected = null; }
xmlTree.prototype.createXMLDOM = function() { //生成XMLDOM对象
var xmldom;
if (window.ActiveXObject){
var xmldom = new ActiveXObject("Microsoft.XMLDOM");
} else {
if (document.implementation && document.implementation.createDocument) {
var xmldom = document.implementation.createDocument("","doc",null);
}
}
xmldom.async = false;
xmldom.resolveExternals = false;
xmldom.validateOnParse = false;
xmldom.preserveWhiteSpace = true;
return xmldom;
}
xmlTree.prototype.createTree = function() { //生成并打印
var xmldom = this.createXMLDOM();
document.write('<div id="tree"><\/div>'); // 树所用层
document.write('<div id="treeTip"><\/div>'); //提示所用层
document.getElementById('treeTip').style.visibility = 'visible';
document.getElementById('treeTip').style.display = 'none';
if (xmldom.load(this.xmlFile)) {
this.createNodes(xmldom);
} else {
this.html = 'Load XML Error';
}
document.getElementById('tree').innerHTML = this.html;
return;
}
xmlTree.prototype.getFirstChildData = function(obj, name) { //取得指定名称节点的第一个子节点的数据
var result = '';
if (typeof(obj) == 'object' && name != null && name != '') {
var node = obj.getElementsByTagName(name);
if (node != null && node.length > 0) {
result = node[0].firstChild.data;
}
}
return result;
}xmlTree.prototype.checkChildNodes = function(obj, id) { //检测是否有分支
var result = false;
var nodes = obj.getElementsByTagName('node');
if (nodes != null && nodes.length > 0) {
//var pid;
for (var i = 0; i < nodes.length; i++) {
//pid = nodes[i].getAttribute('parentid');
if (nodes[i].getAttribute('parentid') == id) {
result = true;
break;
}
}
}
return result;
}xmlTree.prototype.createNodes = function(obj, id) { //生成指定编号节点的树
if (typeof(id) == 'undefined') id = null; //如果没有id传入则为根节点
var nodes = obj.getElementsByTagName('node');
if (nodes != null && nodes.length > 0) {
var modeClass, modeSrc, iconClass, iconSrc;
var nid, npid, nname, nicon, nlink, ntarget, nexplain, hasChildNodes;
//判断模式类型,并应用样式
modeClass = 'close';
modeSrc = this.iconPath + this.iconClose;
if (this.mode == 1) {
modeSrc = this.iconPath + this.iconOpen;
modeClass = 'open';
}
if (id == null) modeClass = 'open'; //若为根节点则显示
this.html += '<ul id="tree_' + id + '_c" class="' + modeClass + '">'; for (var i = 0; i < nodes.length; i++) {
npid = nodes[i].getAttribute('parentid');
if (npid == id) {
//初始化
modeClass = 'close'; iconClass = 'icon-file'; iconSrc = this.iconPath + this.iconFile; //取得节点编号并检测
nid = nodes[i].getAttribute('id');
this.html += '<li id="tree_' + nid + '"><span onclick="' + this.name + '.action(this,event);" onmouseover="' + this.name + '.action(this,event);" onmouseout="' + this.name + '.action(this,event);">';
//取得节点自定义图标
//判断是否含有子节点,并确定箭头和图标的图片及样式
nicon = this.getFirstChildData(nodes[i], 'icon');
hasChildNodes = this.checkChildNodes(obj, nid);
if (hasChildNodes) {
iconClass = '';
iconSrc = this.iconPath + this.iconFolder;
this.html += '<img id="tree_' + nid + '_a" src="' + modeSrc + '" class="arrow" \/>'; //箭头
}
if (nicon != '') iconSrc = nicon;
this.html += '<img id="tree_' + nid + '_i" src="' + iconSrc + '" class="' + iconClass + '" \/>'; //图标 //取得节点连接
nlink = this.getFirstChildData(nodes[i], 'link');
if (nlink != '') {
nlink = ' href="' + nlink + '"';
} else {
nlink = ' href="javascript:;"';
} //取得节点目标
ntarget = this.getFirstChildData(nodes[i], 'target');
if (ntarget != '') {
ntarget = ' target="' + ntarget + '"';
} //取得节点说明
nexplain = this.getFirstChildData(nodes[i], 'explain');
if (nexplain != '') {
nexplain = ' onmouseover="' + this.name + '.treeTips(\'' + nexplain + '\');" onmouseout="' + this.name + '.treeTips();"'
} //取得节点名称
nname = this.getFirstChildData(nodes[i], 'name');
this.html += '<a id="tree_' + nid + '_l" onclick="' + this.name + '.action(this,event);"' + nlink + ntarget + nexplain + '>' + nname + '<\/a><\/span>'; //obj.documentElement.removeChild(nodes[i]);
if (hasChildNodes) this.createNodes(obj, nid); //迭代子节点 this.html += '<\/li>';
}
}
this.html += '<\/ul>';
}
return;
}xmlTree.prototype.action = function(obj, e) { //节点操作
e = e ? e : (window.event ? window.event : null); //获取操作类型
e = e.type;
if (obj.tagName == 'A') {
try { this.prevSelected.className = '';}
catch(e) {}
this.prevSelected = obj;
obj.className = 'selected';
}
if (obj.tagName == 'SPAN') {
var arrow = obj.firstChild; //取得箭头对象
var borther = obj;
while (borther.tagName != 'UL') { //取得分支对象
borther = borther.nextSibling;
if (borther == null) break;
}
if (borther != null) {
switch (e) { //检测操作类型并执行相应代码
case 'click':
if (borther.className == 'open') {
borther.className = 'close';
arrow.src = this.iconPath + this.iconClose;
} else {
borther.className = 'open';
arrow.src = this.iconPath + this.iconOpen;
}
break;
case 'mouseover':
if (arrow.tagName == 'IMG' && borther.className == 'close') {
arrow.src = this.iconPath + this.iconOver;
}
break;
case 'mouseout':
if (arrow.tagName == 'IMG' && borther.className == 'close') {
arrow.src = this.iconPath + this.iconClose;
}
break;
}
}
}
return;
}xmlTree.prototype.treeTips = function(msg) { //提示栏
if (this.prevTip != null) clearTimeout(this.prevTip);
var obj = document.getElementById('treeTip');
if (obj != null) {
if (this.treeTips.arguments.length < 1) { // hide
obj.style.display = 'none';
} else { // show
obj.innerHTML = msg;
this.prevTip = setTimeout('document.getElementById("treeTip").style.display = "block"',300);
document.onmousemove = this.moveToMouseLoc;
}
}
return;
}xmlTree.prototype.moveToMouseLoc = function(e) { //移动到鼠标所在位置
var obj = document.getElementById('treeTip');
if (obj != null) {
var offsetX = -10, offsetY = 20;
var x = 0, y = 0;
if (window.event) {
x = event.x + document.body.scrollLeft;
y = event.y + document.body.scrollTop;
} else {
x = e.pageX;
y = e.pageY;
}
obj.style.left = x + offsetX + 'px';
obj.style.top = y + offsetY + 'px';
}
return;
} var tree = new xmlTree("tree");
tree.mode = 1;
tree.createTree();
</script>
但是运行显示不出来。
麻烦看一下下,如何实现?