function addFile() { var file = this.files[0]; if (!/image\/\w+/.test(file.type)) { alert('上传的不是图片'); this.value = ""; return false; } var obj = this; var objUrl = getObjectURL(file); var image = new Image(); image.src = objUrl; image.onload = function () { if (this.width != 338 || this.height != 338) { alert("文件尺寸不正确!"); obj.value = ""; return false; } //alert("图片的宽度为" + this.width + ",长度为" + this.height); }; return true; }