我有一個小問題,一直在竊聽我,我似乎無法找到一個可行的解決方案。我有一個字符串,它來自以下格式的xml文檔。JavaScript - decodeURI渲染爲HTML
var str="<p><a href="http://antwrp.gsfc.nasa.gov/apod/ap131120.html"><img src="http://antwrp.gsfc.nasa.gov/apod/calendar/S_131120.jpg" align="left" alt="What are black hole jets made of?" border="0" /></a> What are black &amp; hole jets made of?</p><br clear="all"/>";
我用
var dec = decodeURI(str);
我想呈現爲HTML,而不是看我得到下面的輸出的輸出。
<p><a href="http://antwrp.gsfc.nasa.gov/apod/ap131120.html"><img src="http://antwrp.gsfc.nasa.gov/apod/calendar/S_131120.jpg" align="left" alt="What are black hole jets made of?" border="0" /></a> What are black & hole jets made of?</p><br clear="all"/>
我試圖發送此解碼數據的HTML文檔與
document.write(dec)
和
document.getElementById("output").innerHTML=dec;
該輸出有什麼問題?我看起來沒問題。另外我不認爲這是decodeURI的輸出......? – Christoph
Youu是正確的decodeURI根本沒有改變字符串。感謝指針 – user2040454