Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在href中插入JavaScript变量?_Java_Javascript_Variables_Href - Fatal编程技术网

如何在href中插入JavaScript变量?

如何在href中插入JavaScript变量?,java,javascript,variables,href,Java,Javascript,Variables,Href,我试图在href中添加一个JavaScript变量 当我使用href时,因为我希望链接显示为Click here,所以它会按原样保留在链接中->{$order.paymentBefore}/{$order.guid},未更改。使用Click event进行如下操作 HTML 在javascript中,包含一个函数,该函数可将的href更改为所需的值。你不能像现在这样使用它 让您的html标记看起来像这样 <a id="hyperlink" href="#">Click Here<

我试图在href中添加一个JavaScript变量

当我使用href时,因为我希望链接显示为Click here,所以它会按原样保留在链接中->{$order.paymentBefore}/{$order.guid},未更改。

使用Click event进行如下操作

HTML


在javascript中,包含一个函数,该函数可将的href更改为所需的值。你不能像现在这样使用它

让您的html标记看起来像这样

<a id="hyperlink" href="#">Click Here</a>

您可以提及href value,直到您拥有的静态值为止,变量可以在onclick call中给出。请参见以下示例:

    var orderLink= "xyz";
     <a style="font-size:large;align-content:center" 
href="http://<static value>" onclick="location.href = this.href + orderLink; return false;"> Click Here </a>

您期望哪个模板引擎将解析该变量?在生成href的函数中创建的变量是什么语言。你不能像以前那样混合html和js。看看这篇帖子:@NikaKvezereli-如果上面的答案对你有用,那么接受答案并投票,这将有助于其他人找到正确的解决方案。这太棒了
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;

}
<a id="hyperlink" href="#">Click Here</a>
function myFunction() { //Call this function whenever you want to update the href
    var link = document.getElementById("hyperlink");
    link.href = "http://google.com/" + $order.paymentBefore + "/" + $order.guid;
}
    var orderLink= "xyz";
     <a style="font-size:large;align-content:center" 
href="http://<static value>" onclick="location.href = this.href + orderLink; return false;"> Click Here </a>