简体   繁体   English

如何在JavaScript中形成动态链接?

[英]How to form dynamic link in JavaScript?

I would like to form a link on the client end. 我想在客户端上形成一个链接。

I think that need to be urlencoded but I am pretty confused with this. 我认为这需要进行urlencode,但是对此我感到很困惑。 Is this right? 这是正确的吗?

var link = document.createElement("a");

//addParams function just replaces the 0th and 1th occurrence with values 

a.link = url.addParams(valueO, value1); // url is /home/testpage.aspx?{0}={1}

I think you should do link.href = escape("<your url>"); 我认为您应该做link.href = escape("<your url>"); plus you need to add some innerHTML - link.innerHTML = 'Click Here'; 另外,您需要添加一些innerHTML- link.innerHTML = 'Click Here';

...and then finally add it into the page at some point. ...然后最终将其添加到页面中。

var link = document.createElement('a');

var href = document.createAttribute('href');

link.setAttribute(href,'http://www.example.com?'+paramKey+'='+paramValue);

link.innerText ="Go here";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM