0

使用以下代码初始化选项卡,然后激活在 url 中选择的选项卡(例如 mypage#this_tab)。问题是在页面加载时它将视图转移到选项卡。随后单击选项卡不会改变视图。如何在页面加载时将视图固定到页面顶部?

<!-- *********** Config tabs -->
<script type="text/javascript">
$(document).ready(function() {
  // When page loads...
  $(".tab_content").hide(); //Hide all content
  if (location.hash != "") {
    $(location.hash).show(); //Show selected tab content
    $("ul.apptabs li:has(a[href="+location.hash+"])").addClass("active").show();
  } else {
    $("ul.apptabs li:first").addClass("active").show(); //Activate first tab
    $(".tab_content:first").show(); //Show first tab content
  }
  // On Click Event
  $("ul.apptabs li").click(function() {

$("ul.apptabs li").removeClass("active"); //Remove any "active" class
$(this).addClass("active"); //Add "active" class to selected tab
$(".tab_content").hide(); //Hide all tab content

var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
$(activeTab).fadeIn(); //Fade in the active ID content
return false;
  });
});
</script>
4

0 回答 0