使用了thymeleaf 模板,網頁寫javascript 的for 循環報錯。
<script type="text/javascript">
function test() {
? ?for (var i=0;i<10;i++) {
? ? ? ?console.log("j:");
? ?}
}
</script>
只要有for 循環就會報,元素內容必須由格式正確的字符數據或標記組成。使用了spring boot 的thymeleaf
模板的原因嗎
<script type="text/javascript">
function test() {
? ?for (var i=0;i<10;i++) {
? ? ? ?console.log("j:");
? ?}
}
</script>
只要有for 循環就會報,元素內容必須由格式正確的字符數據或標記組成。使用了spring boot 的thymeleaf
模板的原因嗎
2018-02-12
舉報
2018-08-10
thymeleaf是嚴格遵循w3c的標準的。在thymeleaf的js中使用&,<,>等符號時會產生這種問題,即使轉義也不行,解決方法:將你的js代碼包裹在
<![CDATA[ ]]>
之中即可