如何在Bootstrap 3.3.4中获取轮播的总数和当前幻灯片数量

时间:2015-09-07 12:02:02

标签: javascript jquery twitter-bootstrap

大家好我想在bootstrap 3.3.4中获取旋转木马的当前幻灯片编号我已经在3版以下使用过该脚本并且工作正常但在版本3.3.4中没有工作任何一个帮助我摆脱这种情况 thnx提前 使用的代码

var totalItems = $('.item').length;
var currentIndex = $('div.active').index() + 1;
$('.num').html(''+currentIndex+'/'+totalItems+'');

$('#myCarousel').carousel({
    interval: 2000
});

$('#myCarousel').bind('slid', function() {
    currentIndex = $('div.active').index() + 1;
   $('.num').html(''+currentIndex+'/'+totalItems+'');
});
.container {
    margin-top: 10px;
}
.num{
    background:#000;
    color:#fff;
    padding:10px;
    width:50px;
    text-align:center;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-theme.min.css" rel="stylesheet"/>
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet"/>

<div class="container">
    <div class="well span9 columns">
        <div id="myCarousel" class="carousel slide">
            <div class="carousel-inner">
                <div class="item active">
                    <img src="http://bootstrapdocs.com/v2.0.3/docs/assets/img/bootstrap-mdo-sfmoma-01.jpg" alt="" />
                </div>
                <div class="item">
                    <img src="http://bootstrapdocs.com/v2.0.3/docs/assets/img/bootstrap-mdo-sfmoma-02.jpg" alt="" />
                </div>
                <div class="item">
                    <img src="http://bootstrapdocs.com/v2.0.3/docs/assets/img/bootstrap-mdo-sfmoma-03.jpg" alt="" />
                </div>
            </div> 
            <a class="left carousel-control" href="#myCarousel" data-slide="prev">‹</a>
            <a class="right carousel-control" href="#myCarousel" data-slide="next">›</a>
        </div>
    </div>
</div>

<div class="num"></div>

但是当我在版本3.3.4中使用时它没有用,请帮助我

1 个答案:

答案 0 :(得分:2)

试试这个:

$('#myCarousel').on('slide.bs.carousel', function() {
    currentIndex = $('div.active').index() + 1;
   $('.num').html(''+currentIndex+'/'+totalItems+'');
});