我有以下代码:
$('ul.questions li a').click(function(event) {
$('.tab').hide();
$($(this).attr('href')).fadeIn('slow');
event.preventDefault();
window.location.hash = $(this).attr('href');
});
这只是根据您单击的时间淡入 div,但我希望页面 URL 哈希标记在您单击时更改,以便人们可以复制它并为其添加书签。目前,当哈希标签更改时,这会有效地重新加载页面。
是否可以通过更改hash标签而不重新加载页面来防止跳转效果?
最佳答案
这对我有用
$('ul.questions li a').click(function(event) {
event.preventDefault();
$('.tab').hide();
window.location.hash = this.hash;
$($(this).attr('href')).fadeIn('slow');
});
查看此处http://jsbin.com/edicu具有几乎相同代码的演示
关于jquery - 在 jQuery 中更改哈希值而无需重新加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1939041/