---
title: "DTree的BUG解决方法"
author: "freeglad"
date: "2008-12-25T15:33:00Z"
tags: []
slug: "dtree-bug"
draft: false
lastmod: "2008-12-25T15:33:00Z"
id: 586540
url: "https://freeglad.iteye.com/blog/586540"
---

dtree.js的BUG  
当dtree条目的URL包括空格时，浏览器将会提示出错。

解决方法如下：  
打开dtree.js源文件，找到 onClick=' + node.url + ''; 这段代码，  
替换为：onClick=\\'' + node.url + '\\'';

dTree.prototype.node = function(node, nodeId) {  
var str = '&lt;div class="dTreeNode"&gt;' + this.indent(node, nodeId);  
if (this.config.useIcons) {  
if (!node.icon) node.icon = (this.root.id == node.pid) ? this.icon.root : ((node.\_hc) ? this.icon.folder : this.icon.node);  
if (!node.iconOpen) node.iconOpen = (node.\_hc) ? this.icon.folderOpen : this.icon.node;  
if (this.root.id == node.pid) {  
node.icon = this.icon.root;  
node.iconOpen = this.icon.root;  
}  
str += '&lt;img id="i' + this.obj + nodeId + '" src="' + ((node.\_io) ? node.iconOpen : node.icon) + '" alt="" /&gt;';  
}  
if (node.url) {

str += '&lt;a id="s' + this.obj + nodeId + '" class="' + ((this.config.useSelection) ? ((node.\_is ? 'nodeSel' : 'node')) : 'node') + '" href=javascript:void(0) onClick=\\'' + node.url + '\\'';  
if (node.title) str += ' title="' + node.title + '"';  
if (node.target) str += ' target="' + node.target + '"';  
if (this.config.useStatusText) str += ' onmouseover="window.status=\\'' + node.name + '\\';return true;" onmouseout="window.status=\\'\\';return true;" ';  
if (this.config.useSelection && ((node.\_hc && this.config.folderLinks) || !node.\_hc))  
str += ' onclick="javascript: ' + this.obj + '.s(' + nodeId + ');"';  
str += '&gt;';  
}  
else if ((!this.config.folderLinks || !node.url) && node.\_hc && node.pid != this.root.id)  
str += '&lt;a href="javascript: ' + this.obj + '.o(' + nodeId + ');" class="node"&gt;';  
str += node.name;  
if (node.url || ((!this.config.folderLinks || !node.url) && node.\_hc)) str += '&lt;/a&gt;';

if(node.ifid){  
str +='&nbsp;&nbsp;&lt;a href=javascript:catedel('+node.id+')&gt;&lt;img width=10 height=10 src=img/redclose.gif&gt;&lt;/a&gt;';

}  
str += '&lt;/div&gt;';  
if (node.\_hc) {  
str += '&lt;div id="d' + this.obj + nodeId + '" class="clip" style="display:' + ((this.root.id == node.pid || node.\_io) ? 'block' : 'none') + ';"&gt;';  
str += this.addNode(node);  
str += '&lt;/div&gt;';  
}

this.aIndent.pop();  
return str;  
};