gsp,groovy,encodeURI组件,内联javascript [英] gsp, groovy, encodeURI component, inline javascript
问题描述
我有这个每个循环的问题
我有一个选择,你选择一个选项,按一个按钮,所选值通过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>
一旦 $ {it}
特殊字符如内联的东西被打破,
有没有这样的可能?
onclick =deleteItem('$ {fieldName}','$ {id}','$ {reloadForm}','encodeURIcomponent($ {it})'
我只是不明白
谢谢提前
当然,当 $ {it}
包含,因为这有效地意味着您的onclick属性的值在第二个
发生时终止。 / p>
encodeURIComponent当然不能帮助你,因为它太晚了 - 你不能调用JavaScript方法来修复破碎的HTML代码。
您想要的是将重写为
& quot;
所以它不会结束属性值。对于哪种方法在你的模板语言中 - 请参考文档。
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 :
<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,
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.
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.
What you want is to have the "
rewritten to "
– so that it does not end the attribute value. For which method does that in your template language – please consult docs.
这篇关于gsp,groovy,encodeURI组件,内联javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!