【发布时间】:2012-03-30 06:01:00
【问题描述】:
我有一些填充数组的 html 图像标签。在页面上 - http://www.digitalbrent.com/lab - 显示了数组中的三个元素。单击按钮后,我需要向它们添加一个类。如果从数组中显示 imgs,则每个类都不同。代码如下:
$(document).ready(function(){ //populates array with images
var shipImgs = $("#thumb_slider").children();
console.log(shipImgs);
$.each(shipImgs,function(i,elem){
var tag = "<img src='" + $(elem).attr('src') + "' alt='space'/>"; // This is how I made the image tags.
imgArr.push(tag);
});
console.log(imgArr);
});
$("#basic_ul").html(imgArr[b] + imgArr[a] + imgArr[c]); //displays the images
imgArr[b].addClass("left_slot");
imgArr[a].addClass("middle_slot");
imgArr[c].addClass("right_slot");
我也尝试过使用数组项周围的选择器 $(imgArr[b]).addClass("left_slot");但这也没有用。
任何建议都将不胜感激。我在stackoverflow上查看了类似的问题,但没有运气。我已经研究这个项目一段时间了,找不到任何东西。
【问题讨论】:
-
对不起,如果您正在查看页面,可能需要按增加按钮才能看到数组