<a href="#" id="imgId"><img width="50" height="50" src="xxx.gif" id="test"></a>
<script>
var imgId=document.getElementById("imgId");
var $img=imgId.getElementsByTagName("img")[0];
$img.onload = function(){
imgSize.call($img);
};
function imgSize(){
var imgObj = new Image();
imgObj.src = this.src;
alert(imgObj.width + "\n" + imgObj.height);
}
</script>
js判断图片加载完成后获取图片实际宽高
最新推荐文章于 2021-08-15 18:04:04 发布