2010-09-22 73 views
0

我不記得發現,但我知道有一種方法使用類似<[CODE在xml中編寫代碼,而沒有與xml保留符號有問題..有誰知道嗎?如何從xml轉義javascript代碼?

+0

參見:[?當是一個腳本標籤內必要CDATA節](http://stackoverflow.com/questions/66837/when-is-a-cdata-section-necessary-within-a-script-tag)和[我應該使用「\] \」>「或」// \] \]>「來將CDATA部分關閉到xHTML中](http://stackoverflow.com/questions/2375217/should-i-use-or-for-closing-a-cdata-section-into-xhtml) – Shog9 2010-09-22 16:26:27

回答

5

是的,使用CDATA - http://www.w3schools.com/xml/xml_cdata.asp

實施例:

<script> 
<![CDATA[ 
function matchwo(a,b) 
{ 
if (a < b && a < 0) then 
    { 
    return 1; 
    } 
else 
    { 
    return 0; 
    } 
} 
]]> 
</script> 
+0

冒着複製例子的答案的自由,以防萬一鏈接死亡/被移動/等。 – 2010-09-22 15:28:41

+0

葉好點。 – Lloyd 2010-09-22 15:34:52

+0

他們可以使一個更容易記住的方式..謝謝! – 2010-09-22 15:40:57