我正在尝试将 JavaScript 变量放入 href
中.
<a href="http://google.com/{$order.paymentBefore}/{$order.guid}">click here</a>
当我使用href
时,因为我希望链接显示为“单击此处”,所以它按原样保留在链接中 --> {$order.paymentBefore}/{$order.guid}
,不变。
最佳答案
使用click event
为 <a>
如下
HTML
<a onclick="redirectTo();">click here</a>
JavaScript函数
function redirectTo(){
var parameter1 = $order.paymentBefore; // some thing like this you can set value for 1st Param.
var parameter2 = $order.guid; // some thing like this you can set value for 2nd Param.
window.location.href="http://google.com/"+parameter1+"/"+parameter2;
}
关于java - 如何在 href 中插入 JavaScript 变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28148155/