<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>用jquery来获得上传图片的尺寸的</title>
</head>
<body>
<input type="file" id="image_file" multiple>
<script src="./lib/jquery-1.8.0.min.js"></script>
<script>
//获取input图片宽高和大小
function getImageWidthAndHeight(id, callback) {
var _URL = window.URL || window.webkitURL;
$("#" + id).change(function (e) {
var file, img;
if ((file = this.files[0])) {
img = new Image();
img.onload = function () {
callback && callback({"width": this.width, "height": this.height, "filesize": file.size});
};
img.src = _URL.createObjectURL(file);
}
});
}
getImageWidthAndHeight('image_file', function (obj) {
console.log(''+obj.width+'-----height:'+obj.height);
});
</script>
<script></script>
</body>
</html>
愿中国青年都摆脱冷气,只是向上走,不必听自暴自弃者流的话。
能做事的做事,能发声的发声。
有一分热,发一分光,就令萤火一般,也可以在黑暗里发一点光,不必等候炬火。
此后如竟没有炬火:我便是唯一的光。
——鲁迅