表单代码(仅取上传文件部分):
<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
原文:https://www.cnblogs.com/YeHuan/p/11366126.html