简体   繁体   English

Bootstrap轮播指标和控件无法从PHP运行

[英]Bootstrap carousel indicators and controls not working from php

I'm using php to search a database in order to get pictures for my Carousel, it loads the pictures, and cycles in time, but whenever I click on the side arrows or the indicators, it does nothing , I tried changing the jQuery version (which seemed to be the solution in all the past questions I checked) but it didn't work... is it because I'm loading it from php? 我正在使用php搜索数据库以获取轮播图片,它会加载图片并及时循环, 但是每当我单击侧面箭头或指示器时,它什么都没有做 ,所以我尝试更改jQuery版本(这似乎是我检查过的所有过去问题的解决方案),但是没有用……是因为我正在从php加载它?

The PHP code: PHP代码:

$count = 0;
forEach($filas as $fila){
        $idimg = $fila['id_imagen'];
        if($count==0){
          $indicator .= '<li data-target="#imagenes" data-slide-to="0" class="active"></li>';
          $inner .= '<div class="item active"><img class="img-responsive center-block" src="getimg.php?id='.$idprod.'&img='.$idimg.'" alt="'.$nprod.'"></div>';
        }else{
          $indicator .= '<li data-target="#imagenes" data-slide-to="'.$count.'"></li>';
          $inner .= '<div class="item"><img class="img-responsive center-block" src="getimg.php?id='.$idprod.'&img='.$idimg.'" alt="'.$nprod.'"></div>';
        }
        $count++;
      }

The HTML markup HTML标记

        <div class="carousel-slide" id="imagenes" data-ride="carousel">
          <ol class="carousel-indicators">
            <?php print("$indicator");?>
          </ol>
          <div class="carousel-inner" role="listbox">
            <?php print("$inner");?>
          </div>

          <!-- Left and right controls -->
          <a class="left carousel-control" href="#imagenes" role="button" data-slide="prev">
            <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
          </a>
          <a class="right carousel-control" href="#imagenes" role="button" data-slide="next">
            <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
          </a>
        </div>

i can't add the comment, so there is my suggestion on the problem. 我无法添加评论,所以我对这个问题有建议。 There reason is jquery carousel fired on $(document).ready() , but you are loading content dynamically, so you need to apply $(..).carousel() after the load or write own trigger for the navigation like so 原因是jquery轮播在$(document).ready()上触发,但是您正在动态加载内容,因此您需要在加载后应用$(..).carousel()或为导航编写自己的触发器,如下所示

$(document).on('#left','click',function(){
  $('.carousel').carousel('prev');
});
  1. Try own navigations. 尝试自己的导航。 Here is the jsfiddle example of the bootstrap carousel navigations methods - https://jsfiddle.net/Lomj9k4j/1/ 这里是引导转盘导航方法的jsfiddle例子- https://jsfiddle.net/Lomj9k4j/1/
  2. Try to fire $('.carousel').carousel() on document ready 尝试在准备好文档上触发$('.carousel').carousel()

    $(document).ready(){ $('.carousel').carousel(); });

usefull link - http://getbootstrap.com/javascript/#carousel 有用的链接-http: //getbootstrap.com/javascript/#carousel

经过很多次尝试后,我终于设法看到了我的错误,对于没有注意到它,我必须绝对道歉,在我的标记上,我键入了class =“ carousel-slide”而不是“ carousel slide” ...,现在已经解决了完美地工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM