gsp, groovy, encodeURI component, inline javascript

被刻印的时光 ゝ 提交于 2019-12-12 01:02:17

问题


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


回答1:


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 &quot; – so that it does not end the attribute value. For which method does that in your template language – please consult docs.



来源:https://stackoverflow.com/questions/15681708/gsp-groovy-encodeuri-component-inline-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!