首页 > 技术文章 > jquery html5 file 上传图片显示图片

ourLifes 2017-02-23 16:01 原文

jquery js 的代码:不同浏览器下的路径

//建立一個可存取到該file的url

function getObjectURL(file) {
    var url = null ;
    if (window.createObjectURL!=undefined) { // basic
        url = window.createObjectURL(file) ;
    } else if (window.URL!=undefined) { // mozilla(firefox)
        url = window.URL.createObjectURL(file) ;
    } else if (window.webkitURL!=undefined) { // webkit or chrome
        url = window.webkitURL.createObjectURL(file) ;
    }
    return url ;
}

显示图像:

 

var strsrc=getObjectURL(this.files[0]);
$("#show_img").attr("src",strsrc);

 

推荐阅读