我正在尝试对 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?
});
最佳答案
您的解决方案即将完成。对于任何寻找解决方案并登陆此处的人:
$('.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
});
关于jquery - 在 Bootstrap 轮播的事件幻灯片中查找元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28216596/