0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

tab遷移

0
Posted at
title.html

/service.html?tab=2

title.js
$(function(){

  function activateTab(index){
    $('.tab-index li').removeClass('active');
    $('.tab-index li').eq(index).addClass('active');

    $('.tab-contents section').removeClass('active');
    $('.tab-contents section').eq(index).addClass('active');
  }

  // クリック時
  $('.tab-index li').on('click', function(){
    const index = $(this).index();
    activateTab(index);
  });

  // URLパラメータ取得
  const params = new URLSearchParams(window.location.search);
  const tab = params.get('tab');

  if(tab !== null){
    activateTab(parseInt(tab));
  } else {
    activateTab(0); // デフォルト
  }

});




0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?