2009-10-13 74 views
0

什麼是使用jQuery爲圖像的父div賦予高度和寬度的最佳方式。如何動態地給div賦予高度和寬度?

<div><img src="source.jpg" width="%width" height="%height" /></div> 

請注意,這裏有多個標籤。 3-4張圖片和DIVS。

感謝進步。

jQuery解決方案將是首選。

+0

您將如何處理該問題以及該方法未能實現? – Lazarus 2009-10-13 11:35:42

回答

3

使用jQuery維度。

添加類每個圖像:

<div><img class='myImage' src="source.jpg" width="%width" height="%height" /></div> 

JS:

$(".myImage").each(function(){ 
    $(this).parent().css({ width: $(this).width(), height: $(this).height() }); 
}); 

就是這樣。

GI

+0

謝謝拉撒路:) – jantimon 2009-10-13 11:59:15