我写了以下代码。当鼠标悬停在按钮上时它们起作用,但在单击时不起作用 这是轮播中按钮的代码。
$(document).ready(function () {
$("#mycarousel").carousel({ interval: 1000 });
$("#carousel-pause").click(function () {
$("#mycarsousel").carousel("pause");
});
$("#carousel-play").click(function () {
$("#mycarousel").carousel("cycle");
});
});
以下是jquery脚本
{{1}}
答案 0 :(得分:1)
您的代码看起来正确。问题很可能是在其他地方...我想。 我用您的设置为您制作了工作代码。
希望我能对您有所帮助。
<!DOCTYPE html>
<html lang="en">
<head>
<title>Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<style>
.carousel-inner > .item > img,
.carousel-inner > .item > a > img {
width: 70%;
margin: auto;
}
</style>
</head>
<body>
<div class="container">
<div id="mycarousel" class="carousel slide">
<!-- Indicators -->
<ol class="carousel-indicators">
<li class="item1 active"></li>
<li class="item2"></li>
<li class="item3"></li>
<li class="item4"></li>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner" role="listbox">
<div class="item active">
<img src="img_chania.jpg" alt="Chania" width="460" height="345">
</div>
<div class="item">
<img src="img_chania2.jpg" alt="Chania" width="460" height="345">
</div>
<div class="item">
<img src="img_flower.jpg" alt="Flower" width="460" height="345">
</div>
<div class="item">
<img src="img_flower2.jpg" alt="Flower" width="460" height="345">
</div>
</div>
</div>
</div>
<div class="btn-group" id="carouselbutton">
<button class="btn btn-danger btn-sm" id="carousel-pause">
<span class="fa fa-pause">PAUSE</span>
</button>
<button class="btn btn-danger btn-sm" id="carousel-play">
<span class="fa fa-play">PLAY</span>
</button>
</div>
<script>
$(document).ready(function(){
$("#mycarousel").carousel({interval: 1000});
// Click on the button to start sliding
$("#carousel-play").click(function(){
$("#mycarousel").carousel("cycle");
});
// Click on the button to stop sliding
$("#carousel-pause").click(function(){
$("#mycarousel").carousel("pause");
});
});
</script>
</body>
</html>