[英]Display the current page's hash/anchor in the page's body with JavaScript
Use window.location.hash
to grab the anchor's name. 使用window.location.hash
获取锚点的名称。
var anchorName = window.location.hash;
Create a text node to display what you want: 创建一个文本节点以显示所需内容:
var path = document.createTextNode("→ " + anchorName);
Add it to the Dom: 将其添加到Dom中:
document.getElementById(idOfContainerYouWantToEdit).appendChild(path);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.