js上传图片及时显示

 1  $("#upfile").change(function(){
 2       var objUrl=getURL(this.files[0]);
 3       if(objUrl){
 4       $("img").attr("src",objUrl); 
 5    }
 6  })
 7 
 8 
 9       function getUrl(file){
10             var url=null;
11             if (window.createObjectURL != undefined) { 
12                 url = window.createObjectURL(file);
13             } else if (window.URL != undefined) { 
14                 url = window.URL.createObjectURL(file);
15             } else if (window.webkitURL != undefined) { 
16                 url = window.webkitURL.createObjectURL(file);
17             }
18             return url;
19       }
原文地址:https://www.cnblogs.com/Evaniko/p/6427635.html