[英]passing parameter to <html:link> from javascript
<html:link href="DemoAction.do?method=val1¶m1=val2">DEMO</html:link>
我怎样才能从javascript传递val1和val2?
Add styleId="myLink"
to the <html:link>
in order to query the element with JavaScript. 将
styleId="myLink"
添加到<html:link>
,以便使用JavaScript查询元素。
Then you can do the following in JS: 然后你可以在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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.