尝试在不重定向的情况下将轮播添加到网页
Trying to add carousel to webpage without redirecting
当我尝试将此代码添加到我的网页时,每当我单击向左或向右箭头时,它都会尝试重定向到“#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>
从您的 <a>
中删除 href="#carousel-example-generic"
。不过,您可能会在悬停时丢失 "hand"。因此,您可能需要添加 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>
用散列替换 <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>
或者直接从 <a>
标签中删除 href
除了 KJ Price 的回答之外,您还可以这样做(我假设您使用的是 jQuery,因为您显然使用的是 Bootstrap):
$('.carousel-control').click(function(e){
e.preventDefault();
});
这样您仍然可以保留 a 标签,但链接不会触发新页面加载。
这不是重定向,而是聚焦轮播的锚点。它应该滚动到 <div id="carousel-example-generic" ...
.
删除 href="javascript:void(0);"
并添加 style="cursor:pointer"
当我尝试将此代码添加到我的网页时,每当我单击向左或向右箭头时,它都会尝试重定向到“#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>
从您的 <a>
中删除 href="#carousel-example-generic"
。不过,您可能会在悬停时丢失 "hand"。因此,您可能需要添加 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>
用散列替换 <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>
或者直接从 <a>
标签中删除 href
除了 KJ Price 的回答之外,您还可以这样做(我假设您使用的是 jQuery,因为您显然使用的是 Bootstrap):
$('.carousel-control').click(function(e){
e.preventDefault();
});
这样您仍然可以保留 a 标签,但链接不会触发新页面加载。
这不是重定向,而是聚焦轮播的锚点。它应该滚动到 <div id="carousel-example-generic" ...
.
删除 href="javascript:void(0);"
并添加 style="cursor:pointer"