Supposed I have the following code:
<html:link onclick="jQuery('#add').data('name','${name}').dialog('open');" href="#">
And with this, if ${name} = a"b"c, problem occ开发者_StackOverflow中文版urs, link was not rendered well. I have tried to escape the value, serialize but maybe my way is wrong.
Any suggestion how to do this? I have been searching, but i just cant find the answer.
Thanks all in advance.
You need to escape your quotes or take it out of the DOM (which I recommend) by putting a listener on it:
$('a').click(function(){
$('#add').data('name','${name}').dialog('open');
});
You must escape your data value, such as html entity. See this link for more details.
And, are you using Struts 2 Framework? Just use <s:property>
and it will escape it for you.
If not, use <c:out>
in jstl, it will help you :)
What about not in-lining JavaScript?
Template
<html:link id="add_name_open_dialog" rel="${name}" href="#">
JavaScript
jQuery("#add_name_open_dialog").click(function(){
jQuery('#add').data('name', $(this).attr("rel")).dialog('open');
});
精彩评论