선택된 메뉴가 몇번째인지 찾아내는 jQuery
$('.nav-tabs a').click(function(){ var idx = $('.nav-tabs a').index(this); alert(idx); $(this).tab('show'); });
또는
$('.nav-tabs li>a').click(function(){ var idx = $('.nav-tabs li>a').index(this); if(idx == 2){ alert(idx + '번째 index를 선택했습니다'); } else { alert(idx); } $(this).tab('show'); });
|
<ul class="nav nav-tabs"> <li class="active"><a data-toggle="tab" href="#menu0">메뉴0</a></li> <li><a data-toggle="tab" href="#menu1">메뉴1</a></li> <li><a data-toggle="tab" href="#menu2">메뉴2</a></li> <li><a data-toggle="tab" href="#menu3">메뉴3</a></li> </ul>
<div class="tab-content"> <div id="menu0" class="tab-pane fade in active"> <h4>Menu 0</h4> <p>Eaque ipsa quae ab illo inventore veritatis. </p> </div> <div id="menu1" class="tab-pane fade"> <h4>Menu 1</h4> <p>Eaque ipsa quae ab illo inventore veritatis. </p> </div> <div id="menu2" class="tab-pane fade"> <h4>Menu 2</h4> <p>Eaque ipsa quae ab illo inventore veritatis. </p> </div> <div id="menu3" class="tab-pane fade"> <h4>Menu 3</h4> <p>Eaque ipsa quae ab illo inventore veritatis. </p> </div> </div> |