在我的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()函数。您可能还想阅读有关此的documentation。
x.description.encodeAsJavaScript()
或在 Controller 中(因为您未使用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()
关于javascript - 用HTML代码破解javascript的Grails字符串(cordova),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23065393/