Jquery 从外部链接跳转到HTML页面的特定部分无效

Jquery 从外部链接跳转到HTML页面的特定部分无效,jquery,html,anchor,hashtag,Jquery,Html,Anchor,Hashtag,我创建了一个页面,该页面内部跳转到div中的特定部分,并具有指定的ID。它(内部)工作正常 我有ID为career div和about div的元素 当我试图用hashtag从另一个页面(比如contact.html)跳转到index.html)时,它没有跳转到特定的部分 <a href="index.html#career-div">Career</a> <div class="container"> <div id="career-div" c

我创建了一个页面,该页面内部跳转到
div
中的特定部分,并具有指定的ID。它(内部)工作正常

我有ID为
career div
about div
的元素

当我试图用hashtag从另一个页面(比如
contact.html
)跳转到
index.html
)时,它没有跳转到特定的部分

<a href="index.html#career-div">Career</a>

<div class="container">
  <div id="career-div" class="content-block-div">
  </div>
</div>

你是怎么做内部跳跃的?你使用锚定标记了吗?是的,我使用锚定标记,如上所述,我使用jquery平滑滚动到目标:::$('a[href*=\\]:not([href=\\]])。单击(function(){……}你需要发布jquery、插件名称和你正在使用的任何相关Javascript。页面将跳转到
使用
$(“#button careers,#button services,#button about,#button home”).removeClass('active');
将使您的脚本更干净。为什么不采取类似的措施,取消浏览器控件,但在window中包装对您自己函数的调用。load.将停止跳转,并在所有情况下提供平滑滚动,包括在index.html#something URI上
<a href="index.html#career-div">Career</a>

<div class="container">
  <div id="career-div" class="content-block-div">
  </div>
</div>
 $(function(){
   $('a[href*=#]:not([href=#])').click(function() {
     if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
       var target = $(this.hash);
       target = target.length ? target : $('[name=' + this.hash.slice(1) +']');

       if (target.length) {
           $('html,body').animate({
             scrollTop: target.offset().top
           }, 1000);

           if(this.hash == '#content-spacer')
           {
             $('#button-home').addClass('active');
             $('#button-about').removeClass('active');
             $('#button-services').removeClass('active');
             $('#button-careers').removeClass('active');
             $('#button-contact').removeClass('active');
           }
           else if(this.hash == '#about-spacer')
           {
             $('#button-about').addClass('active');
             $('#button-home').removeClass('active');
             $('#button-services').removeClass('active');
             $('#button-careers').removeClass('active');
             $('#button-contact').removeClass('active');
           }
           else if(this.hash == '#services-spacer')
           {
             $('#button-services').addClass('active');
             $('#button-about').removeClass('active');
             $('#button-home').removeClass('active');
             $('#button-careers').removeClass('active');
             $('#button-contact').removeClass('active');
           }
           else if(this.hash == '#career-spacer')
           {
             $('#button-careers').addClass('active');
             $('#button-services').removeClass('active');
             $('#button-about').removeClass('active');
             $('#button-home').removeClass('active');
             $('#button-contact').removeClass('active');
           }
           else if(this.hash == '#contact-spacer')
           {
             $('#button-contact').addClass('active');
             $('#button-careers').removeClass('active');
             $('#button-services').removeClass('active');
             $('#button-about').removeClass('active');
             $('#button-home').removeClass('active');
           }
           return false;
       }
     } 
  });
});