我试图使用replace方法更改带有哈希值的URL(document.location.hash),但它无法生效。
$(function(){
var anchor = document.location.hash;
//this returns me a string value like '#categories'
$('span').click(function(){
$(window).attr('url').replace(anchor,'#food');
//try to change current url.hash '#categories'
//with another string, I stucked here.
});
});
我不想改变/刷新页面,只是想替换URL而不产生任何响应。
注意:我不想使用 href="#food" 方案来解决这个问题。
location.hash = '#food';
- Fabrício Matté