首页 > 其他 > 详细

JQ 获取 input file 图片 显示在对应位置

时间:2019-11-20 14:53:13      阅读:183      评论:0      收藏:0      [点我收藏+]
$(‘.c_showFile‘).on(‘change‘,function(){
				var c_showImg =this.files[0];
				getObjectURL(c_showImg);
			})

			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);
				}
				$(‘.file‘).css("background-image","url("+url+")");
				$(‘.file‘).css("background-size","100% 100%")
				return url;
			}

 

兼容性没有经过测试。需要用到的小伙伴请根据需求使用。

JQ 获取 input file 图片 显示在对应位置

原文:https://www.cnblogs.com/wxhhts/p/11897678.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!