简体   繁体   English

gsp,groovy,encodeURI组件,内联javascript

[英]gsp, groovy, encodeURI component, inline javascript

i have a problem with this each loop 我每个循环都有问题

i have a select, you choose an option, press a button and the selected value is beamed via ajax as encodeURIcomponent to the backend, the answer updates this ul : 我有一个选择,选择一个选项,按一个按钮,然后选定的值通过ajax作为后端的encodeURIcomponent进行传输,答案将更新此ul:

<g:each in="${items}">
<li class="${fieldName}_item" >${it}<span onclick="deleteItem('${fieldName}','${id}','${reloadForm}', '${it}');" class="editdropdel ${fieldName}_button"></span></li>
</g:each>

as soon as ${it} contains special characters like " "" " the inline stuff is broken, 只要${it}包含特殊字符(如“”),内联的东西就会损坏,

is there something like this possible ? 有这样的可能吗?

onclick="deleteItem('${fieldName}','${id}','${reloadForm}', 'encodeURIcomponent(${it})');"

i just don´t get it 我就是不明白

thankws in advance 预先感谢

Of course this breaks when ${it} contains " , because this effectively means that the value of your onclick attribute gets terminated where the second " occurs. 当然,当${it}包含" ,这会中断,因为这实际上意味着您的onclick属性的值在第二个"出现的地方终止。

encodeURIComponent can of course not help you here, because it “comes too late” – you can not call a JavaScript method to fix broken HTML code. encodeURIComponent当然不能在这里为您提供帮助,因为它“来晚了” –您无法调用JavaScript方法来修复损坏的HTML代码。

What you want is to have the " rewritten to &quot; – so that it does not end the attribute value. For which method does that in your template language – please consult docs. 您想要的是将"重写为&quot;这样它就不会以属性值结尾。对于您的模板语言中的哪种方法,请咨询文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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