js兼容火狐获取图片宽和高的方法

  作者:bea

本文实例讲述了js兼容火狐获取图片宽和高的方法。分享给大家供大家参考。具体实现方法如下: <!doctype html> <html> <head> <meta content="text/html; charset=GBK" http-equiv="Content-Type" /> <title>获取Image 宽高</title></head> <body><scri
本文实例讲述了js兼容火狐获取图片宽和高的方法。分享给大家供大家参考。具体实现方法如下:


<!doctype html>
<html>
<head>
<meta content="text/html; charset=GBK" http-equiv="Content-Type" />
<title>获取Image 宽高</title>
</head>
<body>
<script>
function newimage(obj) {
a = new Image();
var objectURL = window.URL.createObjectURL(obj.files[0]);
var img= document.getElementById('img')
img.src = objectURL;
a.src = objectURL;
img.onload=function (){
alert(img.width);
alert(img.height);
}
}
</script>
<input id="idcardfile" type="file" name="idcardfile"
onchange="newimage(this)"/>
<img id="img" style="display: none;">
</body>
</html>



希望本文所述对大家的javascript程序设计有所帮助。


有用  |  无用

猜你喜欢