javascript - Jquery 数组与图像的迭代

标签 javascript jquery arrays push each

var imgLink = ['ONYX', 'Bristol_Blue_B_002_10', 'Oakhampton_B_001_10-1', 'Quartet_KitchenCountertop_500x342', 'Eternal-Serena_RS11277_Silestone-Kitchen', 'zodiaq_provence_kitchen_2200x1467-b94f5-1', 'Eternal-Serena_RS11277_Silestone-Kitchen-1', 'Ecobycosentino-', 'Hanstone', 'IceStone-Forest-Fern-Shadowlight-Vignette-Kitchen-Countertop', 'RS833_Silversilk_OA-hpr-copy_CMYK', 'scalea'];

    var imgArray = [];

jQuery.each(imgLink, function(i){
    var img = jQuery('<img/>')

    .attr("src", "http://www.link.com/wp-content/uploads/2017/10/" +imgLink[i]+ ".jpg")
    imgArray.push(img[i]);  
});
console.log(imgArray);

大家好,我上面有一段代码,我的目标是制作一个带有属性的数组图像,但现在的结果是

Results of array

JSFiddle

有人可以告诉我我做错了什么吗,谢谢!

最佳答案

您有一个拼写错误。

imgArray.push(img[i]);  

应该是:

imgArray.push(img); // <-- img is not an array

关于javascript - Jquery 数组与图像的迭代,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46695705/

相关文章:

javascript - JQuery html 表通过多个属性进行搜索

IE 中的 Javascript 错误(翻转)

javascript - Leaflet 相当于 google toSpan() 函数

jquery - 使用导航箭头制作幻灯片

Javascript:将包含日期的数组按降序排序

javascript - 需要网格和功能动态使用 jquery/javascript

jquery - 如何在使用 event.preventDefault() 后触发事件

c# - 检查数组中的多个元素是否包含相同的值

arrays - 使用数组排序重新排列 vue 中的元素在移动设备上不起作用?

php - 不要单独处理行,也不包含表元数据