代码之家  ›  专栏  ›  技术社区  ›  LauraNMS

在引导转盘的活动幻灯片中查找元素

  •  1
  • LauraNMS  · 技术社区  · 11 年前

    我正在尝试对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?
    
    
        });
    
    2 回复  |  直到 11 年前
        1
  •  2
  •   annismckenzie    10 年前

    您的解决方案几乎已完成。对于搜索解决方案并在此处登录的任何人:

    $('.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
    });
    
        2
  •  1
  •   MTCoster    11 年前

    而不是使用 carouselData.getItemIndex ,为什么不直接操作该元素?

    carouselData.$element.find('.item.active .description').text("New content here");