[英]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.