gpt4 book ai didi

javascript - 可以替换 window.location.hash 吗?

转载 作者:IT王子 更新时间:2023-10-29 03:15:51 26 4
gpt4 key购买 nike

我想知道是否可以更改 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com