Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
假设用户访问页面http://somedomain.com/path/file.html#foo,我想使用 JavaScript 在页面某处显示如下文本:
→ foo
用于window.location.hash获取锚点的名称。
window.location.hash
var anchorName = window.location.hash;
创建一个文本节点以显示您想要的内容:
var path = document.createTextNode("→ " + anchorName);
将其添加到 Dom:
document.getElementById(idOfContainerYouWantToEdit).appendChild(path);