lysvanilla 2012-09-17 19:01
浏览 276
已采纳

XML+ JS创建树形菜单时当href包含&符号是创建失败

[code="html"]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">


DSTree

<br> body,td{font:12px verdana}<br> #treeBox{background-color:#fffffa;}<br> #treeBox .ec{margin:0 5 0 5;}<br> #treeBox .hasItems{font-weight:bold;height:20px;padding:3 6 0 6;margin:2px;cursor:hand;color:#555555;border:1px solid #fffffa;}<br> #treeBox .Items{height:20px;padding:3 6 0 6;margin:1px;cursor:hand;color:#555555;border:1px solid #fffffa;}<br>

<br> //code by star 20003-4-7<br> var HC = &quot;color:#990000;border:1px solid #cccccc&quot;;<br> var SC = &quot;background-color:#efefef;border:1px solid #cccccc;color:#000000;&quot;;<br> var IO = null;<br> function initTree(){<br> var rootn = document.all.menuXML.documentElement;<br> var sd = 0;<br> document.onselectstart = function(){return false;}<br> document.all.treeBox.appendChild(createTree(rootn,sd));<br> }<br> function createTree(thisn,sd){<br> var nodeObj = document.createElement(&quot;span&quot;);<br> var upobj = document.createElement(&quot;span&quot;);<br> with(upobj){<br> style.marginLeft = sd*10;<br> className = thisn.hasChildNodes()?&quot;hasItems&quot;:&quot;Items&quot;;<br> innerHTML = &quot;<img src=expand.gif class=ec>&quot; + thisn.getAttribute(&quot;text&quot;) +&quot;&quot;;</p> <p>onmousedown = function(){<br> if(event.button != 1) return;<br> if(this.getAttribute(&quot;cn&quot;)){<br> this.setAttribute(&quot;open&quot;,!this.getAttribute(&quot;open&quot;));<br> this.cn.style.display = this.getAttribute(&quot;open&quot;)?&quot;inline&quot;:&quot;none&quot;;<br> this.all.tags(&quot;img&quot;)[0].src = this.getAttribute(&quot;open&quot;)?&quot;expand.gif&quot;:&quot;contract.gif&quot;;<br> }<br> if(IO){<br> IO.runtimeStyle.cssText = &quot;&quot;;<br> IO.setAttribute(&quot;selected&quot;,false);<br> }<br> IO = this;<br> this.setAttribute(&quot;selected&quot;,true);<br> this.runtimeStyle.cssText = SC;<br> }<br> onmouseover = function(){<br> if(this.getAttribute(&quot;selected&quot;))return;<br> this.runtimeStyle.cssText = HC;<br> }<br> onmouseout = function(){<br> if(this.getAttribute(&quot;selected&quot;))return;<br> this.runtimeStyle.cssText = &quot;&quot;;<br> }<br> oncontextmenu = contextMenuHandle;<br> onclick = clickHandle;<br> }</p> <p>if(thisn.getAttribute(&quot;treeId&quot;) != null){<br> upobj.setAttribute(&quot;treeId&quot;,thisn.getAttribute(&quot;treeId&quot;));<br> }<br> if(thisn.getAttribute(&quot;href&quot;) != null){<br> upobj.setAttribute(&quot;href&quot;,thisn.getAttribute(&quot;href&quot;));<br> }<br> if(thisn.getAttribute(&quot;target&quot;) != null){<br> upobj.setAttribute(&quot;target&quot;,thisn.getAttribute(&quot;target&quot;));<br> }</p> <p>nodeObj.appendChild(upobj);<br> nodeObj.insertAdjacentHTML(&quot;beforeEnd&quot;,&quot;<br>&quot;)</p> <p>if(thisn.hasChildNodes()){<br> var i;<br> var nodes = thisn.childNodes;<br> var cn = document.createElement(&quot;span&quot;);<br> upobj.setAttribute(&quot;cn&quot;,cn);<br> if(thisn.getAttribute(&quot;open&quot;) != null){<br> upobj.setAttribute(&quot;open&quot;,(thisn.getAttribute(&quot;open&quot;)==&quot;true&quot;));<br> upobj.getAttribute(&quot;cn&quot;).style.display = upobj.getAttribute(&quot;open&quot;)?&quot;inline&quot;:&quot;none&quot;;<br> if( !upobj.getAttribute(&quot;open&quot;))upobj.all.tags(&quot;img&quot;)[0].src =&quot;contract.gif&quot;;<br> }</p> <p>for(i=0;i<nodes.length;cn.appendChild(createTree(nodes[i++],sd+1)));<br> nodeObj.appendChild(cn);<br> }<br> else{<br> upobj.all.tags("img")[0].src ="endnode.gif";<br> }<br> return nodeObj;<br> }<br> window.onload = initTree;<br> function clickHandle(){ // your code here } function contextMenuHandle(){ event.returnValue = false; var treeId = this.getAttribute("treeId"); // your code here }




<?xml version="1.0" encoding="GB2312"?>































by sTar
2003-4-8


[/code]

其中
的href中包含&字符,创建树失败,但是去掉&role=1,即不包含role时创建成功。
求解决办法。

  • 写回答

1条回答 默认 最新

  • jinnianshilongnian 2012-09-17 19:07
    关注

    xml & 是个实体引用

    1、改成&
    com.sunline.bdss.cbrc_rept.reptMgrMaintance.flow?typeId=3&role=1

    2、<![CDATA[com.sunline.bdss.cbrc_rept.reptMgrMaintance.flow?typeId=3&role=1]]>

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 YOLO检测微调结果p为1
  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题