测试后可用
<html>
<head>
<title>测试</title>
<meta charset="utf-8"/>
<link rel="stylesheet" href="http://g.tbcdn.cn/tb/global/2.9.1/global-min.css">
<script src="http://g.tbcdn.cn/??kissy/k/1.4.2/seed-min.js"></script>
</head>
<body>
<form action="" method="post">
<input type="file" id="uploader" onchange="imgUpload()"/>
<input type="submit" id="submit" onclick="test()"/>
</form>
<div id="tip1"></div>
<div id="tip2"></div>
<script type="text/javascript">
var width;
var height;
function imgUpload() {
var obj=document.getElementById('uploader');
if(obj.files&&obj.files[0]){
var oFile=obj.files[0];
var reader=new FileReader();
reader.onload=function(){
// 也可以用 window.URL.createObjectURL(this.result)
var oImg=new Image();
oImg.src=this.result;
document.body.appendChild(oImg);
oImg.onload=function(){
width=oImg.offsetWidth;
height=oImg.offsetHeight;
//width=oImg.width;
//height=oImg.height;
document.body.removeChild(oImg);//放弃预览
};
};
reader.readAsDataURL(oFile);
}else{//ie 8
var img = new Image();
img.src = document.getElementById('uploader').value;
width=img.width;
height=img.height;
}
}
function test(){
alert(width);
alert(height);
}
</script>
</html>
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有