2013-02-18 42 views

回答

0
$('img').each(function() { 

    var width = $(this).width(); 

    // OR 

    var width = this.clientWidth; 

    // to set that width to image try 

    $(this).attr('width', width); 

    // according to comment: how to assign width to parent li 

    $(this).parent('li').css('width', width + 'px'); 
}); 
+0

我嘗試這樣: '$( '#myGallery IMG')每個(函數(){$ (本)的CSS( '寬度',this.width); });' 它的作品,它給我所有的圖像他們的寬度,但我怎麼能給這個寬度的父母李... – user2084110 2013-02-18 17:32:12

+0

@ user2084110檢查我的更新 – thecodeparadox 2013-02-18 17:33:28

+0

完美的作品!非常感謝您的幫助。 – user2084110 2013-02-18 17:37:54