菜鸟学堂
在线运行
源代码
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Bootstrap 实例 - 轮播(Carousel)插件事件</title> <link rel="stylesheet" href="http://edu.jb51.net/libs/bootstrap/3.3.7/css/bootstrap.min.css"> <script src="http://edu.jb51.net/libs/jquery/2.1.1/jquery.min.js"></script> <script src="http://edu.jb51.net/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script> </head> <body> <div id="myCarousel" class="carousel slide"> <ol class="carousel-indicators"> <li data-target="#myCarousel" data-slide-to="0" class="active"></li> <li data-target="#myCarousel" data-slide-to="1"></li> <li data-target="#myCarousel" data-slide-to="2"></li> </ol> <div class="carousel-inner"> <div class="item active"> <img src="slide1.png" alt="First slide"></div> <div class="item"> <img src="slide2.png" alt="Second slide"></div> <div class="item"> <img src="slide3.png" alt="Third slide"></div> </div> <a class="carousel-control left" href="#myCarousel" data-slide="prev">‹</a> <a class="carousel-control right" href="#myCarousel" data-slide="next">›</a></div> <script>$(function() { $('#myCarousel').on('slide.bs.carousel', function() { alert("当调用 slide 实例方法时立即触发该事件。"); }); });</script> </body> </html>
运行结果
在线运行
菜鸟学堂 edu.jb51.net