How to loop through each image with the same class name?

Possible Duplicate:
jQuery to loop through elements with the same class

I am trying to loop through my images that have a class.

for(var i=0; i<sizes.length; i++){
    var imageSize=sizes[i];
    $('.image').width(imageSize);
}

I have 10 images with the same class name, however, I want them to have different image size.

The loop will loop 10 times but I am not sure how to make each image has the specific imagesize .

Can anyone help me with it? My brain is almost fry. Thanks so much!


如果所有图像都有一类.image ,则可以简单地执行以下操作

$( '.image' ).each( function ( index ) {
    $( this ).css( 'width', sizes[ index ] );
});

You could do something like this:

$('.image').each(function(i) {
    $(this).width(sizes[i]);
});

But you would have to make sure that the sizes array contains the correct sizes in the same order that the images appear on the page.

链接地址: http://www.djcxy.com/p/83502.html

上一篇: 在DOM中访问多个具有相同名称的项目

下一篇: 如何循环使用相同类名的每个图像?