使用 Grails 在执行警报的事件处理程序中转义双引号
根据这个类似的帖子,我尝试了以下方法,但没有-有效,但有错误提示:
onclick="alert('This is my \"quoted text:\"');" (no browser response)
onclick="alert('This is my \\"quoted text:\\"'); (no browser response)
onclick="alert('This is my "quoted text:"');" (comes out as: This is my "quoted text:")
onclick="alert('This is my \x22quoted text:\x22');" (grails .gsp page preprocessor chokes on this)
除了将警报放入函数之外,还有什么想法吗?我想有办法在 html/javascript 中做到这一点吗?
注意:我更新了标题以限定使用 Grails 的问题。下面的所有解决方案通常都可以正常工作,但不适用于 grails 1.3.7。根据 MaxArt 的指示,在上面的版本 4 中,有效的方法是在每个反斜杠之前添加一个额外的反斜杠。
Per this similar post, I tried the following but none-worked, with error noted to side:
onclick="alert('This is my \"quoted text:\"');" (no browser response)
onclick="alert('This is my \\"quoted text:\\"'); (no browser response)
onclick="alert('This is my "quoted text:"');" (comes out as: This is my "quoted text:")
onclick="alert('This is my \x22quoted text:\x22');" (grails .gsp page preprocessor chokes on this)
Any ideas, other than putting the alert into a function? I imagine there is a way to do this in html/javascript?
NOTE: I updated the title to qualify the question for using Grails. All the solutions below may well work in general, but not in grails 1.3.7. What did work, per MaxArt's direction, is adding an additional backslash before each backslash, in version 4 above.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最后一种形式是正确的。我不知道 Grails 如何处理这个问题,但您可以尝试避开反斜杠。
您始终可以决定(这实际上是更好的做法)将事件侦听器附加到元素,而不是使用传统的事件声明。这应该在主体加载后执行:
当然,对于 Internet Explorer 使用
attachEvent
attachEvent
9.这应该是你的元素:
The last form is the correct one. I don't know how Grails handles that, but you may try to escape the backslashes.
You can always resolve to (and it's actually a better practice) attach an event listener to the element rather than using the traditional event declaration. This should be executed after the body has loaded:
Of course, use
attachEvent
for Internet Explorer < 9.And this should be your element:
您是否尝试过
另一种选择。
Have you tried
Just another option.