前端之家收集整理的这篇文章主要介绍了
获取图片地址,前端预览,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
$(document).on(‘change’,‘.upload-item input’,function(){
var file = this.files[0];
// var fr = new FileReader();
// var $Box = $(this).siblings(‘.upload-img-Box’);
// layer.load();
// fr.onload = function(ele){
// layer.closeAll(‘load’);
// var imageURL = ele.target.result;
// $Box.css({
// ‘backgroundImage’: ‘url(‘+imageURL+’)’
// }).removeClass(‘hide’);
// }
// fr.onerror = function(ele){
// layer.closeAll(‘load’);
// layer.msg(‘图片选择失败’,{icon: 0});
// }
// fr.readAsDataURL(file);
var URL = window.URL || window.webkitURL;
var imageURL = URL.createObjectURL(file);
var $Box = $(this).siblings(‘.upload-img-Box’);
$Box.css({
‘backgroundImage’: ‘url(‘+imageURL+‘)’
}).removeClass(‘hide’);
});