html上传图片的预览功能实现

html上传图片的预览功能实现,第1张

概述表单代码(仅取上传文件部分): <input class="selectImg" style="position:absolute;opacity: 0;width:100px;height:100px;" type="file" name="coverChart" onchange="showImg(this)">   js代码: // 图片预览function showImg(obj) {

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

<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]) + "‘)");}// 不同浏览器获得图片urlfunction 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

总结

以上是内存溢出为你收集整理的html上传图片的预览功能实现全部内容,希望文章能够帮你解决html上传图片的预览功能实现所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1038388.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-24
下一篇 2022-05-24

发表评论

登录后才能评论

评论列表(0条)

保存