[英]Display javascript code with text()
我正在嘗試使用jQuery
text()
方法在pre / code標簽內顯示一些javascript
。 像這樣:
jQuery(".output").wrapInner( "<pre><code></code></pre>" );
jQuery(".output code").text("<script type='text/javascript' src='http://somedomain/?" + apiKeyValue.val() + "></script>");
但是腳本標記會產生一個
Uncaught SyntaxError: Unexpected token ILLEGAL
控制台中的錯誤。 如何顯示腳本標簽?
更換
jQuery(".output code").text("<script type='text/javascript' src='http://somedomain/?" + apiKeyValue.val() + "></script>");
有:
jQuery(".output code").text("<script type='text/javascript' src='http://somedomain/?" + apiKeyValue.val() + "></"+"script>");
要么:
jQuery(".output code").text("<script type='text/javascript' src='http://somedomain/?" + apiKeyValue.val() + "><\/script>");
您需要破壞</script>
標記( "</"+"script>"
)或轉義/
( "<\\/script>"
)
如TreeTree在評論中所指出的那樣,有關詳細說明,請閱讀為什么用document.write()編寫時拆分<script>標簽?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.