当我尝试将此代码添加到我的网页时,每当我点击左箭头或右箭头时,它都会尝试重定向到“#carousel-example-generic”,有没有办法在不离开当前网页的情况下执行此操作网页?
下面是代码:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<link href="http://www.cssscript.com/wp-includes/css/sticky.css" rel="stylesheet" type="text/css">
<title>Slideshow Test</title>
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
</head>
<body>
<div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#carousel-example-generic" data-slide-to="0" class="active"></li>
<li data-target="#carousel-example-generic" data-slide-to="1"></li>
<li data-target="#carousel-example-generic" data-slide-to="2"></li>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner">
<div class="item active">
<img src="/temp/0.jpg" alt="...">
<div class="carousel-caption" style="text-shadow: 5px 5px 10px #000000;">
</div>
</div>
<div class="item">
<img src="/temp/1.jpg" alt="...">
<div class="carousel-caption">
<h3>Caption Text</h3>
</div>
</div>
<div class="item">
<img src="/temp/2.jpg" alt="...">
<div class="carousel-caption">
<h3>Caption Text</h3>
</div>
</div>
</div>
<!-- Controls -->
<a class="left carousel-control" href="#carousel-example-generic" role="button" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left"></span>
</a>
<a class="right carousel-control" href="#carousel-example-generic" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right"></span>
</a>
</div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<script src='http://ajax.googleapis.com/ajax/libs/angularjs/1.2.21/angular.min.js'></script>
</body>
</html>
答案 0 :(得分:4)
除了KJ Price的回答,你可以这样做(我假设你使用的是jQuery,因为你明显使用了Bootstrap):
$('.carousel-control').click(function(e){
e.preventDefault();
});
这样你仍然可以保留一个标签,但链接不会触发新的页面加载。
答案 1 :(得分:0)
从href="#carousel-example-generic"
删除<a>
。但是当你徘徊时,你可能会失去“手”。因此,您可能希望添加href="javascript:void(0);"
。
如此:
<a class="left carousel-control" href="javascript:void(0);" role="button" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left"></span>
</a>
<a class="right carousel-control" href="javascript:void(0);" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right"></span>
</a>
答案 2 :(得分:0)
将哈希替换为<a>
代码href
链接:
<a class="left carousel-control" href="#" role="button" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left"></span>
</a>
<a class="right carousel-control" href="#" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right"></span>
</a>
或者只需从href
代码
<a>
即可
答案 3 :(得分:0)
这不是重定向,而是一个专注于旋转木马的锚点。它应该滚动到<div id="carousel-example-generic" ...
。
删除href="javascript:void(0);"
并添加style="cursor:pointer"