jQuery获取file宽高的代码如下,仅在火狐中测试了,其他浏览器兼容性未知。
- var _URL = window.URL || window.webkitURL;
- $("#file").change(function (e) {
- var file, img;
- if ((file = this.files[0])) {
- img = new Image();
- img.onload = function () {
- alert(this.width + " " + this.height);
- };
- img.src = _URL.createObjectURL(file);
- }
- });