2017-06-23 80 views

回答

0

$('#tabs').on('click','li',function(e){ 
 

 
var tab = $(this).data('tab'); 
 

 
$('.pane.' + tab).addClass('active').siblings('.pane.active').removeClass('active'); 
 

 
});
.pane { 
 
display:none; padding:20px; 
 
} 
 
.pane.active { 
 
display:block; 
 
} 
 
#tabs { 
 
display:table; margin:0; padding:0; 
 
} 
 
#tabs li { 
 
display:table-cell; background:blue; color:white; padding:10px; cursor:pointer; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 

 

 
<ul id="tabs"> 
 
<li data-tab="one">One</li> 
 
<li data-tab="two">Two</li> 
 
<li data-tab="three">Three</li> 
 
<li data-tab="four">Four</li> 
 
</ul> 
 

 
<div class="pane one active"> 
 
One data 
 
</div> 
 
<div class="pane two"> 
 
Two data 
 
</div> 
 
<div class="pane three"> 
 
Three data 
 
</div> 
 
<div class="pane four"> 
 
Four data 
 
</div>