Grails字符串与html代码破解javascript(cordova)

Grails String with html code breaking javascript(cordova)

本文关键字:javascript cordova 破解 代码 字符串 html Grails      更新时间:2023-09-26

在我的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>

但是,当我试图恢复字符串以在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()