Scheda JS Bootstrap


Scheda JS (tab.js)

Le schede vengono utilizzate per separare il contenuto in riquadri diversi in cui ogni riquadro è visualizzabile uno alla volta.

Per un tutorial sulle schede, leggi il nostro tutorial su schede/pillole Bootstrap .


Le classi di plug-in Tab

Class Description Example
.nav nav-tabs Creates navigation tabs
.nav-justified Makes navigation tabs/pills equal widths of their parent, at screens wider than 768px. On smaller screens, the nav tabs are stacked
.tab-content Together with .tab-pane and data-toggle="tab", it makes the tab toggleable
.tab-pane Together with .tab-content and data-toggle="tab", it makes the tab toggleable

Via dati-* Attributi

Aggiungi data-toggle="tab"a ciascuna scheda e aggiungi una .tab-paneclasse con un ID univoco per ogni scheda e raggruppale in una .tab-contentclasse.

Esempio

<ul class="nav nav-tabs">
  <li class="active"><a data-toggle="tab" href="#home">Home</a></li>
  <li><a data-toggle="tab" href="#menu1">Menu 1</a></li>
</ul>

<div class="tab-content">
  <div id="home" class="tab-pane fade in active">
    <h3>HOME</h3>
    <p>Some content.</p>
  </div>
  <div id="menu1" class="tab-pane fade">
    <h3>Menu 1</h3>
    <p>Some content in menu 1.</p>
  </div>
</div>


Tramite JavaScript

Abilita manualmente con:

Esempio

// Select all tabs
$('.nav-tabs a').click(function(){
  $(this).tab('show');
})

// Select tab by name
$('.nav-tabs a[href="#home"]').tab('show')

// Select first tab
$('.nav-tabs a:first').tab('show')

// Select last tab
$('.nav-tabs a:last').tab('show')

// Select fourth tab (zero-based)
$('.nav-tabs li:eq(3) a').tab('show')

Opzioni scheda

None

Metodi della scheda

La tabella seguente elenca tutti i metodi di tabulazione disponibili.

Method Description Try it
.tab("show") Shows the tab

Tab Eventi

La tabella seguente elenca tutti gli eventi della scheda disponibili.

Event Description Try it
show.bs.tab Occurs when the tab is about to be shown.
shown.bs.tab Occurs when the tab is fully shown (after CSS transitions have completed)
hide.bs.tab Occurs when the tab is about to be hidden
hidden.bs.tab Occurs when the tab is fully hidden (after CSS transitions have completed)

Suggerimento: usa event.target e event.relatedTarget di jQuery per ottenere la scheda attiva e la scheda attiva precedente:

Esempio

$('.nav-tabs a').on('shown.bs.tab', function(event){
  var x = $(event.target).text();         // active tab
  var y = $(event.relatedTarget).text();  // previous tab
});