1
我想知道如何在不同的li中獲取每個圖像寬度(多個寬度),然後通過jQuery將該寬度返回給每個圖像。jQuery獲取每個圖像的寬度,然後將css寬度添加到每個圖像
所有圖像有不同的寬度。
謝謝你的幫助。
我想知道如何在不同的li中獲取每個圖像寬度(多個寬度),然後通過jQuery將該寬度返回給每個圖像。jQuery獲取每個圖像的寬度,然後將css寬度添加到每個圖像
所有圖像有不同的寬度。
謝謝你的幫助。
$('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');
});
我嘗試這樣: '$( '#myGallery IMG')每個(函數(){$ (本)的CSS( '寬度',this.width); });' 它的作品,它給我所有的圖像他們的寬度,但我怎麼能給這個寬度的父母李... – user2084110 2013-02-18 17:32:12
@ user2084110檢查我的更新 – thecodeparadox 2013-02-18 17:33:28
完美的作品!非常感謝您的幫助。 – user2084110 2013-02-18 17:37:54