我正在尝试对Bootstrap 3旋转木马内的div做一些事情。但是我怎么找到那个div?
$('.carousel').on('slid.bs.carousel', function () {
var carouselData = $(this).data('bs.carousel');
var currentIndex = carouselData.getItemIndex(carouselData.$element.find('.item.active'));
//now I know the current item, but how do I change the .description div
//inside that item?
});
答案 0 :(得分:2)
您的解决方案已基本完成。对于任何寻找解决方案并登陆的人来说:
$('.carousel').on('slid.bs.carousel', function (e) {
// mind the e parameter I added ^ here
var carouselData = $(this).data('bs.carousel');
var currentIndex = carouselData.getItemIndex($(e.relatedTarget));
// but that is unnecessary because the current slide is in e.relatedTarget
var currentItem = $(e.relatedTarget);
// currentItem is the current slide's div, use it
});
答案 1 :(得分:1)
为什么不直接操纵那个元素而不是carouselData.getItemIndex
?
carouselData.$element.find('.item.active .description').text("New content here");