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