js 函数

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 ;
}

调用

document.getElementById('Jbtn').onchange = function() {
    var strsrc=getObjectURL(this.files[0]);
    $("#show_img").attr("src",strsrc);
}

Posted on 2018-01-10 15:02  LY_Young  阅读(2720)  评论(0编辑  收藏  举报