[英]Grails String with html code breaking javascript(cordova)
在我的grails應用程序中,我有這個字符串
String description = "<p>Some long description here that shows me the message in javascript</p><span data-icon=\"pushpin\"><p>But here doesnt give me any message in javascript"</p>
但是,當我嘗試恢復String來執行警報或javascrip中的某些操作時,在我的cordova項目中:
var button = '<button type="button" onclick="getInfo("' + x.description + '")">More infomation</button>';`
它只給我第一個<p></p>
並在按鈕內書寫,我從字符串"pushpin"
知道它,但是有一種方法可以修復""
或''
?
我不想使用jQuery。
我懷疑您的問題是由於呈現值時雙引號/單引號沒有被轉義這一事實引起的。 嘗試使用encodeAsJavascript()函數。 您可能還需要閱讀有關此文檔 。
x.description.encodeAsJavaScript()
或在控制器中(因為您未使用GSP)
def String description = "<p>Some long description here that shows me the message in javascript</p><span data-icon=\"pushpin\"><p>But here doesnt give me any message in javascript</p>".encodeAsJavaScript()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.