FileReader 对象容许Web应用程序异步读取存储在用户计算机上的文件(或原始数据缓冲区)的内容,使用 File
或 Blob
对象指定要读取的文件或数据。异步
//回显图片预览 function preImg(sourceId) { var url; var imgPre = document.getElementById("Photo"); //回显img标签 if (navigator.userAgent.indexOf("MSIE")>=1) { // IE url = sourceId.value; } else if(navigator.userAgent.indexOf("Firefox")>0) { // Firefox url = window.URL.createObjectURL(sourceId.files.item(0)); } else if(navigator.userAgent.indexOf("Chrome")>0) { // Chrome url = window.URL.createObjectURL(sourceId.files.item(0)); }else{ url = window.URL.createObjectURL(sourceId.files.item(0)); } imgPre.src = url; }