这是我使用的最终版本:
<script type="text/javascript">
jQuery(document).ready(function($) {
$('button#play').click(function() {
if ($(this).text() == 'Pause') {
$(this).text('Play');
$(this).attr('aria-label', 'Play');
} else {
$(this).text('Pause');
$(this).attr('aria-label', 'Pause');
}
});
$(function() {
var tabCarousel = setInterval(function() {
var tabs = $('#tab-carousel .nav-tabs > li'),
active = tabs.filter('.active'),
next = active.next('li'),
toClick = next.length ? next.find('a') : tabs.eq(0).find('a');
if(!$('#play').hasClass('active')) {
toClick.trigger('click');
}
}, 6000);
});
});
</script>
这是页面代码:
<div id="tab-carousel" class="tabbable tabs-left">
<ul class="nav nav-tabs">
<li><a href="#tab1" data-toggle="tab">Tab 1</li>
<li><a href="#tab2" data-toggle="tab">Tab 2</li>
<li><a href="#tab3" data-toggle="tab">Tab 3</li>
<li><a href="#tab4" data-toggle="tab">Tab 4</li>
</ul>
<div class="tab-content">
<div class="tab-pane" id="tab1"><p>Content here.</p></div>
<div class="tab-pane" id="tab2"><p>Content here.</p></div>
<div class="tab-pane" id="tab3"><p>Content here.</p></div>
<div class="tab-pane" id="tab4"><p>Content here.</p></div>
<div class="pull-right"><button id="play" type="button" class="btn btn-primary btn-small" data-toggle="button" title="Pause">Pause</button>
</div>
</div>
</div>