文件上传预览(前端)

2020-11-19  本文已影响0人  银角大王__
$("#fileUpload1").change(function () {
    var files =$("#fileUpload1")[0].files[0]
    var urls =   getObjectURL(files)
    $("#fileList1").empty();
    $("#fileList1").append(
        '<embed src="'+urls+'" type="application/pdf">'
        // '<img src="'+urls+'"  height="50px" alt="">'
    )
    console.log(files,urls);
});

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 ;
}
上一篇下一篇

猜你喜欢

热点阅读