2011-01-27 116 views
9

目前我正在與jQuery的圖像滑塊。我已經從網上下載了代碼。我的代碼演示是here如何去除高度和寬度?

我的問題是:我如何刪除動態附加到圖像標籤的高度和寬度作爲內聯樣式?

謝謝。如果你想設置的「原始」圖像尺寸試試這個

$('your-image').css({ 
    width: '', 
    height: '' 
}); 

+0

你能指望它刪除後的高和寬是? 0? – ajma 2011-01-27 06:06:43

+0

我希望如果我刪除高度和寬度,那麼它必須採取原來的高度和寬度,而不是代碼分配給他們的那個.. – rajeshrt 2011-01-27 06:19:48

回答

9

嘗試使用此代碼

$('your-image').css({ 
    width: 'auto', 
    height: 'auto' 
}); 
11

爲了讓所有的工作方式,你需要刪除屬性和CSS。 這是我的代碼工作。

$('your-image') 
    .removeAttr("width").removeAttr("height") 
    .css({ width: "", height: "" }); 
1

這是一個非常簡單的jQuery解決方案。我在wpwizard.net找到了答案。

這裏的網址:http://wpwizard.net/jquery/remove-img-height-and-width-with-jquery/

這裏是jQuery的:

<script src="http://code.jquery.com/jquery-latest.js"></script> 
<script type="text/javascript"> 
jQuery.noConflict(); 
jQuery(document).ready(function($){ 

    $('img').each(function(){ 
     $(this).removeAttr('width') 
     $(this).removeAttr('height'); 
    }); 

}); 
</script> 
0
$('img').width('auto').height('auto'); 
0

繼承可能的方式之一。

$('your-image').css({ width: "inherit", height: "inherit" });

相關問題