基于锚定的选项卡导航jquery代码不工作

基于锚定的选项卡导航jquery代码不工作,jquery,Jquery,为什么“李”元素没有被激活 尝试访问=> 您正在将类添加到锚点,而不是li 请尝试以下方法: var url = document.location.toString(); if (url.match('#')) { // the URL contains an anchor // click the navigation item corresponding to the anchor var myAnchor = '#' + url.s

为什么“李”元素没有被激活

尝试访问=>


您正在将类添加到锚点,而不是li

请尝试以下方法:

var url = document.location.toString();
        if (url.match('#')) { // the URL contains an anchor
          // click the navigation item corresponding to the anchor
          var myAnchor = '#' + url.split('#')[1];
          $("ul.tabs li").removeClass("active"); //Remove any "active" class
          $("ul.tabs li a:" + myAnchor).addClass("active"); //Add "active" class to selected tab
          $(".tab_content").hide(); //Hide all tab content
          $(myAnchor).fadeIn(); //Fade in the active ID content
        }
$("ul.tabs li a:" + myAnchor).parent().addClass("active");

用于获取选项卡的选择器已关闭。您的选择器是
“ul.tabs li a:#meta_info”
,它不是真正的选择器。您想查找href为“#meta_info”的a。请尝试以下方法:

var url = document.location.toString();
        if (url.match('#')) { // the URL contains an anchor
          // click the navigation item corresponding to the anchor
          var myAnchor = '#' + url.split('#')[1];
          $("ul.tabs li").removeClass("active"); //Remove any "active" class
          $("ul.tabs li a:" + myAnchor).addClass("active"); //Add "active" class to selected tab
          $(".tab_content").hide(); //Hide all tab content
          $(myAnchor).fadeIn(); //Fade in the active ID content
        }
$("ul.tabs li a:" + myAnchor).parent().addClass("active");

对我有用。你能发布一些你拥有的html吗?至少在Chrome/OSX中是这样。如果你发布html,只需在jsfiddle.net上发布即可;更简单。为什么不使用
window.location.hash
而不是拆分URL。第一次访问网页并使用锚定标记打开它时,所有选项卡都不会显示为活动状态。将显示选项卡的内容。一旦页面加载,尝试单击其他选项卡,您就会知道。