如何绑定数据属性而不是id?

时间:2018-04-04 12:25:32

标签: jquery html5 css3 owl-carousel-2

使用bootstrap 3轮播 - Fiddle



/* for testing only */

.item img {
  width: 100%;
  height: auto
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>


<div data-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" role="listbox">
    <div class="item active">
      <img src="http://placehold.it/450x350" alt="Slide 1">
      <div class="carousel-caption">
        Caption Slide 1
      </div>
    </div>
    <div class="item">
      <img src="http://placehold.it/450x350" alt="Slide 2">
      <div class="carousel-caption">
        Caption Slide 2
      </div>
    </div>
    <div class="item">
      <img src="http://placehold.it/450x350" alt="Slide 3">
      <div class="carousel-caption">
        Caption Slide 3
      </div>
    </div>
  </div>

  <!-- Controls -->
  <a class="left carousel-control" href="#carousel-example-generic" role="button" data-slide="prev">
    <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
    <span class="sr-only">Previous</span>
  </a>
  <a class="right carousel-control" href="#carousel-example-generic" role="button" data-slide="next">
    <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
    <span class="sr-only">Next</span>
  </a>
</div>
&#13;
&#13;
&#13;

bootstrap documentationid使用carousel

<!-- Carousel -->
<div id="carousel-example-generic" class="carousel slide" data-ride="carousel">

<!-- Carousel Indicators -->
<li data-target="#carousel-example-generic" data-slide-to="1"></li>

<!-- Carousel Controls -->
<a class="left carousel-control" href="#carousel-example-generic" data-slide="prev">

我想用id代替data attribute(data-id)

<!-- Carousel -->
<div data-id="carousel-example-generic" class="carousel slide" data-ride="carousel">

如果您使用数据属性 - 那么分页和导航不起作用

如何将数据属性绑定到滑块的分页和导航?

谢谢

我很乐意提供任何帮助

0 个答案:

没有答案