App下載
首頁javascriptimgjQuery HTML Element - 如何獲取在css中自動的圖像寬度

jQuery HTML Element - 如何獲取在css中自動的圖像寬度

我們想知道如何獲取在css中自動的圖像寬度。

<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-1.9.1.js'></script>
<script type='text/javascript'>
$(function(){
    $(document).ready(function() {
        $("img").load(function() {
            console.log($(this).height());
            console.log($(this).width());
        });
    });
});
</script>
</head>
<body>
  <img src="http://m.o2fo.com/style/download.png"
    alt="Smiley face">
</body>
</html>