简体   繁体   English

用HTML代码破解javascript的Grails字符串(cordova)

[英]Grails String with html code breaking javascript(cordova)

In my grails application I have this String 在我的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>

But when I try to recover the String to do an alert or something in javascrip, in my cordova project: 但是,当我尝试恢复String来执行警报或javascrip中的某些操作时,在我的cordova项目中:

var button = '<button type="button" onclick="getInfo("' + x.description + '")">More infomation</button>';`

It only gives me the me the first <p></p> and writes inside the button, I know its from the String "pushpin" but there's a way to fix the "" or '' ? 它只给我第一个<p></p>并在按钮内书写,我从字符串"pushpin"知道它,但是有一种方法可以修复""''

I'd like to not use jQuery. 我不想使用jQuery。

I suspect your issues come from the fact the double/single quotes aren't escaped when the value is rendered. 我怀疑您的问题是由于呈现值时双引号/单引号没有被转义这一事实引起的。 Try using the encodeAsJavascript() function. 尝试使用encodeAsJavascript()函数。 You may also want to read the documentation about this. 您可能还需要阅读有关此文档

x.description.encodeAsJavaScript()

Or in the controller (since you aren't using GSP) 或在控制器中(因为您未使用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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM