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]]>

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

报告相同问题?

悬赏问题

  • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)
  • ¥20 Python安装cvxpy库出问题
  • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误
  • ¥15 python天天向上类似问题,但没有清零
  • ¥30 3天&7天&&15天&销量如何统计同一行
  • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
  • ¥15 C#调用python代码(python带有库)
  • ¥15 活动选择题。最多可以参加几个项目?
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题