表单代码(仅取上传文件部分):

<input class="selectImg" style="position:absolute;opacity: 0;width:100px;height:100px;" type="file" name="coverChart" onchange="showImg(this)">

 

js代码:

// 图片预览
function showImg(obj) {
    $(".doShow").css("background-image", "url('" + getObjectURL(obj.files[0]) + "')");
}

// 不同浏览器获得图片url
function getObjectURL(file) {
    var url = null;
    if (window.createObjectURL != undefined) {
        url = window.createObjectURL(file) ;
    } else if (window.URL != undefined) {
        url = window.URL.createObjectURL(file) ;
    } else if (window.webkitURL != undefined) {
        url = window.webkitURL.createObjectURL(file) ;
    }
    return url;
}

 

参考链接:https://blog.csdn.net/man_zuo/article/details/83115212

相关文章:

  • 2022-12-23
  • 2023-03-20
  • 2021-11-13
  • 2021-09-25
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-05-18
  • 2021-10-14
  • 2021-12-20
  • 2021-07-05
  • 2021-12-21
  • 2022-12-23
  • 2022-02-03
相关资源
相似解决方案