2017-10-11 86 views
0

我試圖生成通過jQuery的有效跨距標籤:Thymeleaf和jQuery報價失敗

  $("#commentsSection").append("<span class='myClass'>"); 

      $("#commentsSection").append("</span>"); 

我使用Spring引導和Thymeleaf和HTML等將不會呈現因:

SyntaxError: missing) after argument list 
$("#commentsSection").append("<span class="myClass">"); 

我應該用esape引號嗎?

回答

1

如果你的javascript直接在html文件中,那麼用CDATA-Block將它包圍起來,這樣thymeleaf就不會嘗試渲染它。

<script> 
    // <![CDATA[ 
    . 
    . your code 
    . 
    // ]]> 
</script> 
+0

它的工作原理,謝謝! – jarosik

0

退出報價或使用'單引號裏面。

$("#commentsSection").append("<span class='myClass'>"); 

$("#commentsSection").append("<span class=\"myClass\">"); 
+0

org.xml.sax.SAXParseException:對於與元素類型「span」關聯的屬性「class」,預期打開引號。 – jarosik

0

你需要把逃生焦炭這樣,

"<span class=\"myClass\">" 

希望工程!

+0

nope,同樣的問題 – jarosik