Grails字符串,带有html代码中断javascript(cordova)

Grails字符串,带有html代码中断javascript(cordova),javascript,grails,cordova,Javascript,Grails,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 descript

在我的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 description=“这里有一些用javascript向我显示消息的长描述

,但这里没有用javascript给我任何消息”

但当我试图恢复字符串以在javascrip中执行警报或其他操作时,在我的cordova项目中:

var button = '<button type="button" onclick="getInfo("' + x.description + '")">More infomation</button>';`
var按钮='更多信息'`
它只给了我第一个

并在按钮内部写入,我从字符串
“pushpin”
中知道它,但有一种方法可以修复


我不想使用jQuery。

我怀疑您的问题是由于在呈现值时没有转义双引号/单引号。尝试使用encodeAsJavascript()函数。您可能还想阅读有关这方面的文章

x.description.encodeAsJavaScript()
或者在控制器中(因为您没有使用GSP)

def String description=“此处的一些长描述以javascript显示消息,但此处没有以javascript提供任何消息。”.encodeAsJavaScript()

另一件事,我没有使用gsp来渲染解码/编码部件。是cordova(编辑了我的问题)。然后在控制器中进行编码。
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()