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.
我想知道是否可以更改 window.location.hash 中的哈希并将其替换为“this.id”。还是我需要更改整个 window.location?
是的你可以。我在我的一个站点上做了类似的事情,虽然用href而不是id,但id也可以。一个简单的例子:
href
id
$('a[id]').click(function(e) { // This will change the URL fragment. The change is reflected // on your browser's address bar as well window.location.hash = this.id; e.preventDefault(); });