【问题标题】:I'm trying to add images to my flickity carousel from an array and using a for loop我正在尝试将图像从数组添加到我的 flickity carousel 并使用 for 循环
【发布时间】:2017-11-12 05:26:57
【问题描述】:

将单元格元素添加到主轮播。 在img标签中放什么有问题

for (let i = 0; i < imageArray.length; i++) {    
    $('.main-carousel').each(function(){

        $(this).append("<div class='carousel-cell'><img 
        src='imageArray???'</div>");
  });
}

【问题讨论】:

  • 在被否决之前提供所有代码添加用于轮播的 html
  • 能不能加一行console.log(imageArray[i]);并返回到记录到控制台的对象之一的问题?我们看到该对象中有什么可用的?提供答案应该很容易。

标签: javascript jquery arrays


【解决方案1】:
var imageArray = ['imageURL1.png', 'imageURL2.png', 'imageURL3.png'];

for (let i = 0; i < imageArray.length; i++) {    
    $('.main-carousel').each(function() {

        $(this).append('<div class='carousel-cell'><img 
        src="'+imageArray[i]+'"></div>');
  });
}

【讨论】:

    猜你喜欢
    • 2014-07-24
    • 2022-01-20
    • 1970-01-01
    • 2016-08-21
    • 2021-07-01
    • 1970-01-01
    • 2020-10-22
    • 1970-01-01
    • 2021-08-05
    相关资源
    最近更新 更多