[英]Multiple IDs in Jquery for image carousel not working
我有一个图像轮播的jquery代码,但是我想在代码中运行多个轮播ID。 #myCarousel工作精美,但是#historyCarousel根本不工作。
我是JS的新手,所以我也不知道如何在需要时将其更改为类(除了将#替换为。之外,我还需要编辑代码)
这是我现在拥有的代码-只有#myCarousel在工作。
jQuery(document).ready(function($) {
$('#myCarousel,#historyCarousel').carousel({
interval: 5000
});
$('#carousel-text').html($('#slide-content-0').html());
//Handles the carousel thumbnails
$('[id^=carousel-selector-]').click( function(){
var id = this.id.substr(this.id.lastIndexOf("-") + 1);
var id = parseInt(id);
$('#myCarousel,#historyCarousel').carousel(id);
});
// When the carousel slides, auto update the text
$('#myCarousel,#historyCarousel').on('slid.bs.carousel', function (e) {
var id = $('.item.active').data('slide-number');
$('#carousel-text').html($('#slide-content-'+id).html());
});
});
轮播构造函数(不确定您使用的是什么)可能期望使用元素(或包含单个项目的列表)而不是选择列表。 在每个循环中尝试以下操作:
$('#myCarousel,#historyCarousel').each(function(idx, el){
$(el).carousel({ interval: 5000 });
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.