我想知道是否可以更改 window.location.hash 中的哈希并将其替换为“this.id”。还是我需要更改整个 window.location?
最佳答案
是的,你可以。我在我的一个网站上做了类似的事情,虽然使用 href
而不是 id
,但是 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();
});
关于javascript - 可以替换 window.location.hash 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3377150/