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       }

 

posted @ 2017-02-22 10:15  SSS.M.AAA  阅读(1268)  评论(0编辑  收藏  举报