jQuery - 在跳转链接后重新加载页面
我正在使用隐藏的 div 创建幻灯片效果。单击缩略图后,相应的 div 将出现在窗口中,而其他 div 将被隐藏。但是,我还需要重新加载页面。我尝试使用这样的东西:
$("a").click(function() {
location.reload();
});
但是,这将重新加载页面而不跟随链接(类似于 href="#div02")。如何让它跟随链接并重新加载页面?
I'm creating a slideshow effect using hidden div's. Once a thumbnail is clicked, the corresponding div appears in a window and the other divs are hidden. However, I also need the page to reload. I attempted to use something like this:
$("a").click(function() {
location.reload();
});
However, this will reload the page without following the link (something like a href="#div02"). How do I get it to both follow the link and reload the page?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果我理解正确的话,你想要的是修改浏览器的 URL 以反映 DOM 的当前状态。这意味着,如果用户单击图片,URL 将通过附加“#div02”进行更新,最终用户将能够与朋友共享此链接,这将直接将他们带到该图片/状态。
如果这就是您想要的,那么您正在寻找位置哈希。设置:
获取:
If I understand you correctly, what you want is to modify the URL of the browser to reflect the current state of the DOM. Meaning, if a user clicked on a picture, the URL would be updated by appending a "#div02" and finally the user would be able to share this link with friends which will take them directly to that picture/state.
If that's what you want, your looking for Location Hash. To set:
To get:
无需重新加载页面,只需删除嵌入上一个视频的元素即可。
Rather than reload the page just remove the element that embeds the previous video.
您可以向当前网址添加额外参数(带有随机值)。由于您的网址已更改,浏览器将重新加载页面,然后跳转到锚点。
You can add an extra parameter (with random value) to to your current url. The browser will reload the page and then jumb to an anchor since your url has changed.