我正在使用php来搜索数据库,以便为我的Carousel获取图片,它会加载图片,并及时循环,但每当我点击侧箭头或指示符时,它什么都不做< / strong>,我尝试更改jQuery版本(这似乎是我检查的所有过去问题的解决方案)但它没有用......是因为我从php加载它?
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++;
}
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>
答案 0 :(得分:0)
我无法添加评论,因此我对此问题提出了建议。
有理由是在$(document).ready()
上触发了jquery轮播,但是你是动态加载内容的,所以你需要在加载后应用$(..).carousel()
或者为导航编写自己的触发器
$(document).on('#left','click',function(){
$('.carousel').carousel('prev');
});
尝试在文档就绪
上触发$('.carousel').carousel()
$(document).ready(){
$('.carousel').carousel();
});
答案 1 :(得分:0)
After a lot of attemps I finally managed to see my error, and I must absolutely apologise for not noticing it, on my markup I typed in class="carousel-slide" instead of "carousel slide"... fixed that and it's now working flawlessly.