参考 http://wrongwaycn.github.io/bootstrap/docs/javascript.html#collapse
同样 启动方式有2种 一种是在div的class中加 另一种是js启动
js可以提供更多控制 假如你只是需要例子中得效果 就用第一种data-attribute 的方式吧
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <link href="../css/bootstrap.css" rel="stylesheet"> <style type="text/css"> </style> </head> <body> <div id="myCarousel" class="carousel slide" style="600px;"> <ol class="carousel-indicators"> <li data-target="#myCarousel" data-slide-to="0" class=""></li> <li data-target="#myCarousel" data-slide-to="1" class="active"></li> <li data-target="#myCarousel" data-slide-to="2" class=""></li> </ol> <div class="carousel-inner"> <div class="item"> <img src="assets/img/bootstrap-mdo-sfmoma-01.jpg" alt=""> <div class="carousel-caption"> <h4>First Thumbnail label</h4> <p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.</p> </div> </div> <div class="item active"> <img src="assets/img/bootstrap-mdo-sfmoma-02.jpg" alt=""> <div class="carousel-caption"> <h4>Second Thumbnail label</h4> <p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.</p> </div> </div> <div class="item"> <img src="assets/img/bootstrap-mdo-sfmoma-03.jpg" alt=""> <div class="carousel-caption"> <h4>Third Thumbnail label</h4> <p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.</p> </div> </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> <script src="../js/jquery-1.8.0.min.js" type="text/javascript"></script> <script src="../js/bootstrap.js" type="text/javascript"></script> </body> </html>
js方式
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <link href="../css/bootstrap.css" rel="stylesheet"> <style type="text/css"> </style> </head> <body> <div id="myCarousel" class="carousel slide" style="600px;"> <!-- Carousel items --> <div class="carousel-inner"> <div class="item"> <img src="assets/img/bootstrap-mdo-sfmoma-01.jpg" alt=""> <div class="carousel-caption"> <h4>First Thumbnail label</h4> <p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.</p> </div> </div> <div class="item active"> <img src="assets/img/bootstrap-mdo-sfmoma-02.jpg" alt=""> <div class="carousel-caption"> <h4>Second Thumbnail label</h4> <p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.</p> </div> </div> <div class="item"> <img src="assets/img/bootstrap-mdo-sfmoma-03.jpg" alt=""> <div class="carousel-caption"> <h4>Third Thumbnail label</h4> <p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.</p> </div> </div> <div class="item"> <img src="assets/img/bootstrap-mdo-sfmoma-03.jpg" alt=""> <div class="carousel-caption"> <h4>Fourth Thumbnail label</h4> <p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.</p> </div> </div> </div> <!-- Carousel nav --> <a id="PreBtn" class="carousel-control left" >‹</a> <a id="NxtBtn" class="carousel-control right" >›</a> </div> </div> <div class="div1 btn" value="0">1</div> <div class="div2 btn" value="1">2</div> <div class="div3 btn" value="2">3</div> <div class="div4 btn" value="3">4</div> <script src="../js/jquery-1.8.0.min.js" type="text/javascript"></script> <script src="../js/bootstrap.js" type="text/javascript"></script> <script type="text/javascript"> $(function(){ $('.carousel').carousel({ interval: 5000 }); $('carousel').carousel('cycle'); $('#PreBtn').click(function(){ $('.carousel').carousel('prev'); }); $('#NxtBtn').click(function(){ $('.carousel').carousel('next'); }); $('.btn').click(function(){ var val=$(this).attr('value'); //alert(val); $('.carousel').carousel(Number(val)); }); }); </script> </body> </html>