java - how to pass dynamic parameters to jquery function -



java - how to pass dynamic parameters to jquery function -

i want pass dynamic paramters jquery onclick event. before, used html , javascript:

class="lang-html prettyprint-override"><!-- html --> <a id="link123" href="link1" onclick="javascript:func1(${param1},${param2});">123</a> class="lang-js prettyprint-override">/* javascript */ func1(param1,param2) { // }

the parameters param1 , param2 come backend code , dynamic. how not of import here.

after using jquery, have html , js:

class="lang-html prettyprint-override"><a href="link123"> <input type="hidden" id="param1" value="${param1}"/> <input type="hidden" id="param2" value="${param2}"/> class="lang-js prettyprint-override">$(document).ready(function() { $("#link123").click(function() { var param1 = $("#param1")[0].value; var param1 = $("#param1")[0].value; func1(param1,param2); }); }); func1(param1,param2) { //do } function func1 there before.

i'm not happy solution (passing params inline hidden values). other, improve ways pass dynamic parameters jquery, in situation this?

data attributes advised purpose. use:

<input data-param1="${param1}" />

and then:

$('input').click(function(){ $(this).attr('data-param1'); });

java javascript jquery html jstl

Comments

Popular posts from this blog

delphi - blogger via idHTTP : error 400 bad request -

c++ - compiler errors when initializing EXPECT_CALL with function which has program_options::variables_map as parameter -

How do I check if an insert was successful with MySQLdb in Python? -