0
<html:link href="DemoAction.do?method=val1¶m1=val2">DEMO</html:link>
如何傳遞VAL1和val2從JavaScript?從JavaScript傳遞參數<html:link>
<html:link href="DemoAction.do?method=val1¶m1=val2">DEMO</html:link>
如何傳遞VAL1和val2從JavaScript?從JavaScript傳遞參數<html:link>
將styleId="myLink"
改爲<html:link>
以便用JavaScript查詢元素。
然後您可以在JS中執行以下操作:
var val1 = "newval1", val2 = "newval2";
// Option 1: Set the href attribute regardless of its current value
var link = document.getElementById("myLink");
link.setAttribute("href", "DemoAction.do?method="+val1+"¶m1="+val2);
// Option 2: Set the href attribute depending on its current value
var link = document.getElementById("myLink"),
hrefParts = link.getAttribute("href").split("?");
link.setAttribute("href", hrefParts[0]+"?method="+val1+"¶m1="+val2);