[英]How do I make JavaScript generate a new link?
我已经为此搜索了很多。 如何让 JS 创建一个链接,使其符合example.com/index.php#number
的内容?
我的意思的例子 - https://gyazo.com/428ea0c819d340a699a328baaf4c1c1f
我不太确定你想在这里实现什么,但我希望这会有所帮助。
let a = document.createElement('a');
let url_link_title = document.createTextNode("Your Title Here.");
a.appendChild(url_link_title);
a.title = "Your Title Here";
a.href = "http://yoursampleaddress.com";
document.body.appendChild(a);
假设您有您的基本地址“http://www.example.com/index.php”,您要做的是向 url 添加一个新部分
const base = "http://www.example.com/index.php"
let number = 42
location.href = base + "#" + number
这会将您重定向到“http://www.example.com/index.php#42”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.