获取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}); }; img.src = _URL.createObjectURL(file); } }); }
这里使用了一个回调方法。
在jQuery中使用:
(function () { getImageWidthAndHeight('image_file', function (obj) { if (obj.width != 843 || obj.height != 1038) { $.messager.alert('操作提示', result.data.msg, '弹窗图片宽高必须是843*1038px'); } }); })(jQuery)