I have a page use fileReader to preview the upload image.
I have test in my local machine, it works fine, but when I test in JS fiddle, it is not working. anyone know where is the problem?
if(window.FileReader){
function preview(input){
if(input.files && input.files[0]) {
var reader = new FileReader();
reader.readAsDataURL(input.files[0]);
reader.onload = function(e){$('#previewImage').attr('src', e.target.result);}
}
}
}else{alert("file reader not support");}
here is fiddle http://jsfiddle.net/s39P3/93/
If you have the console open you will see the error is that the 'preview' function isn't found, because it isn't part of the scope. I added it to the window scope so window.preview = function()
and now it works.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.