CodeLab
Show Output
 
xxxxxxxxxx
19
 
1
<!DOCTYPE html>
2
<html lang="en">
3
<head>
4
<meta charset="utf-8">
5
<title>JavaScript Find Current Image Width and Height</title>
6
<script>
7
    function imgSize(){
8
        var myImg = document.querySelector("#sky");
9
        var currWidth = myImg.clientWidth;
10
        var currHeight = myImg.clientHeight;
11
        alert("Current width=" + currWidth + ", " + "Original height=" + currHeight);
12
    }
13
</script>
14
</head>
15
<body>
16
    <img src="/examples/images/sky.jpg" id="sky" width="250" alt="Cloudy Sky">
17
    <p><button type="button" onclick="imgSize();">Get Current Image Size</button></p>
18
</body>
19
</html>
 

在微博、微信、公众号、小程序分享此示例。 如果您觉得有帮助,请给我们一个赞。