Javascript jQuery脚本#url更改

Javascript jQuery脚本#url更改,javascript,jquery,Javascript,Jquery,我正在使用滚动页面(div)。如果在url中键入#+项(编号),将获得所需的页面(div)。但是,在菜单中导航时,url不会相应更改 如何获取url,以便在通过菜单导航脚本时相应地更改 还有,有没有办法从url(#item02)中删除“item”,只留下数字? 或者更好的是,每个页面(div)都有自定义的名称 函数resizePanel(){ 宽度=$(窗口).width(); 高度=$(窗口).height(); 遮罩宽度=宽度*$(“.item”)。长度; $(“#调试”).html();

我正在使用滚动页面(div)。如果在url中键入#+项(编号),将获得所需的页面(div)。但是,在菜单中导航时,url不会相应更改

如何获取url,以便在通过菜单导航脚本时相应地更改

还有,有没有办法从url(#item02)中删除“item”,只留下数字? 或者更好的是,每个页面(div)都有自定义的名称


函数resizePanel(){
宽度=$(窗口).width();
高度=$(窗口).height();
遮罩宽度=宽度*$(“.item”)。长度;
$(“#调试”).html();
$(“.wrapper.item”).css({});
$(“.mask”).css({});
$(.wrapper”).scrollTo($(.a.selected”).attr(“href”),0}
$(文档).ready(函数(){
$(“a.panel”)。单击(函数(){
$(“a.panel”).removeClass(“选定”);
$(此).addClass(“选定”);
当前=$(本);
$(.wrapper”).scrollTo($(this.attr(“href”),800);
返回false;
});
$(窗口).resize(函数(){resizePanel()})
})

在您的clickhandler中,您可以向您的位置添加哈希,如下所示:

$("a[href=#item4]").unbind().click(function(e){
  e.preventDefault();

  // scroll to desired container
  $(".wrapper").scrollTo($(this).attr("href"),800, function(){
      // update location
      var url = window.location.origin + window.location.pathname,     
      hash = '#item4';   
      window.location.href = url + hash; 
  });
});

由于您绕过了正常的书签链接行为,因此需要使用类似History.js的工具来管理浏览器历史记录和散列链接。似乎无法使其正常工作<代码>$(“#item4”)。单击(函数(){var url=window.top.location.origin+window.top.location.pathname,hash='#/contact';window.location.href=url+hash;})是,因为选择器错误。尝试以下操作:
$([href=#item4])。单击(函数(){var url=window.top.location.origin+window.top.location.pathname,hash='#/contact';window.location.href=url+hash;})它现在可以工作了。然而,这又带来了另一个问题。动画不起作用。谢谢你的尝试。然而,同样的问题仍然存在。解除绑定添加了…仍然没有任何内容:(
$("a[href=#item4]").unbind().click(function(e){
  e.preventDefault();

  // scroll to desired container
  $(".wrapper").scrollTo($(this).attr("href"),800, function(){
      // update location
      var url = window.location.origin + window.location.pathname,     
      hash = '#item4';   
      window.location.href = url + hash; 
  });
});