这个对我有用:)
http://jsfiddle.net/4WY6S/6/
<script type="text/javascript">
var currentPage =0;
$('#myCarousel').carousel({
interval: 7000
})
$('#carousel-nav a').click(function(q){
q.preventDefault();
clickedPage = $(this).attr('data-to')-1;
currentPage = clickedPage-1;
$('#myCarousel').carousel(clickedPage);
});
var pages = $("#carousel-nav a");
var pagesCount = pages.length;
$('#myCarousel').on('slide', function(evt) {
$(pages).removeClass("active");
currentPage++;
currentPage=(currentPage%pagesCount);
$(pages[currentPage]).addClass("active");
});
</script>
这是“上一个”和“下一个”按钮的代码:
<a href="#" onclick="if(currentPage>0){currentPage=((currentPage-2)%3);$('#myCarousel').carousel(currentPage+1);}">PREVIOUS</a> | <a href="#" onclick="if(currentPage<2){$('#myCarousel').carousel(currentPage+1);}">NEXT</a>