0
<html:link href="DemoAction.do?method=val1&param1=val2">DEMO</html:link>

我如何从 javascript 传递 val1 和 val2 ?

4

1 回答 1

2

添加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+"&param1="+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+"&param1="+val2);
于 2013-10-20T01:28:36.290 回答