方法千千万万种、此处只有一种
此文为整理篇,之前从哪儿看的忘记了
<html>
<head>
<script type="text/javascript" src="https://cdn.staticfile.org/jquery/1.9.1/jquery.min.js"></script>
<script>
$(function(){
$("#pstimg").change(function(){
var file = this.files[0];
console.log(file);
alert("文件大小:"+(file.size / 1024).toFixed(1)+"kB");
if (window.FileReader) {
var reader = new FileReader();
reader.readAsDataURL(file);
//监听文件读取结束后事件
reader.onloadend = function (e) {
console.log(e.target.result,file.fileName)
showXY(e.target.result,file.fileName);
};
}
});
});
function showXY(source){
var img = document.getElementById("loc_img");
img.src = source;
alert("Width:"+img.width+", Height:"+img.height);
}
</script>
</head>
<body>
<input type="file" name="pstimg" id="pstimg"/>
<img src="" id="loc_img" />
<body>
</html>