var MyTest = document.getElementById("upload_img").files[0]; var reader = new FileReader();reader.readAsDataURL(MyTest);reader.onload = function(theFile) { var image = new Image(); image.src = theFile.target.result; image.onload = function() { alert("图片的宽度为"+this.width+",长度为"+this.height); };};
其中,id为“upload_img”的标签如下: