当我的 event.value 是 == 到 / 时,我需要从 url 中删除 #。我有一个带有 jquery.address 的 lighbox,它存储对打开图像的引用,当我关闭它时,我需要删除 # 标记,因为这会导致窗口滚动到顶部。
我成功地删除了 # 标记:window.location.href.slice(0, -1); 但正如您在上面的代码中看到的那样,这会导致页面加载时 url 重写,而不仅仅是在我的事件之后。
只有当我完成时,我如何才能链接这个 javascript,就像我关闭灯箱时这个函数被称为 olny 一样。
我在这里附上我的代码和注释。谢谢你们
$.address.change(function(event) {
curLink = event.value;
if(curLink != '/') {
// here my stuff, jquery.address generates url with reference
// ex: mysite.com/cat/subcat/page.html#one
} else {
$('#element').animate({opacity:"0"},{duration:100, easing:"quartEaseOut", complete: function () {
// here I need to remove the hash only after the complete
// ex: mysite.com/cat/subcat/page.html# > mysite.com/cat/subcat/page.html
window.location.href.slice(0, -1);
$(this).hide();
}});
}
});