<html:link href="DemoAction.do?method=val1¶m1=val2">DEMO</html:link>
我如何从 javascript 传递 val1 和 val2 ?
<html:link href="DemoAction.do?method=val1¶m1=val2">DEMO</html:link>
我如何从 javascript 传递 val1 和 val2 ?
添加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);