图片预览
Posted 站在西瓜上的猪
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了图片预览相关的知识,希望对你有一定的参考价值。
function upImg(obj){ var imgFile = obj.files[0]; console.log(imgFile); var img = new Image(); var fr = new FileReader(); fr.onload = function(){ var htmlStr = ‘<div class="upWrap">‘; htmlStr += ‘<div class="fileWrap">‘; htmlStr += ‘<input type="file" accept="image/gif,image/jpeg,image/jpg,image/png,image/svg" onchange="upImg(this)"/>‘; htmlStr += ‘</div>‘; htmlStr += ‘<div class="imgWrap upedImg"><span class="deleteImg">X</span>‘; htmlStr += ‘<img src="‘+fr.result+‘" />‘; htmlStr += ‘</div>‘; htmlStr += ‘</div>‘; $(‘.imgOnloadWrap‘).append(htmlStr); obj.value = ‘‘; } fr.readAsDataURL(imgFile); }
1 function upImg(obj){ 2 var imgFile = obj.files[0]; 3 console.log(imgFile); 4 var img = new Image(); 5 var fr = new FileReader(); 6 fr.onload = function(){ 7 var htmlStr = ‘<div class="upWrap">‘; 8 htmlStr += ‘<div class="fileWrap">‘; 9 htmlStr += ‘<input type="file" accept="image/gif,image/jpeg,image/jpg,image/png,image/svg" onchange="upImg(this)"/>‘; 10 htmlStr += ‘</div>‘; 11 htmlStr += ‘<div class="imgWrap upedImg"><span class="deleteImg">X</span>‘; 12 htmlStr += ‘<img src="‘+fr.result+‘" />‘; 13 htmlStr += ‘</div>‘; 14 htmlStr += ‘</div>‘; 15 $(‘.imgOnloadWrap‘).append(htmlStr); 16 obj.value = ‘‘; 17 } 18 fr.readAsDataURL(imgFile); 19 }
function upImg(obj){ var imgFile = obj.files[0]; console.log(imgFile); var img = new Image(); var fr = new FileReader(); fr.onload = function(){ var htmlStr = ‘<div class="upWrap">‘; htmlStr += ‘<div class="fileWrap">‘; htmlStr += ‘<input type="file" accept="image/gif,image/jpeg,image/jpg,image/png,image/svg" onchange="upImg(this)"/>‘; htmlStr += ‘</div>‘; htmlStr += ‘<div class="imgWrap upedImg"><span class="deleteImg">X</span>‘; htmlStr += ‘<img src="‘+fr.result+‘" />‘; htmlStr += ‘</div>‘; htmlStr += ‘</div>‘; $(‘.imgOnloadWrap‘).append(htmlStr); obj.value = ‘‘; } fr.readAsDataURL(imgFile); }
1 function upImg(obj){ 2 var imgFile = obj.files[0]; 3 console.log(imgFile); 4 var img = new Image(); 5 var fr = new FileReader(); 6 fr.onload = function(){ 7 var htmlStr = ‘<div class="upWrap">‘; 8 htmlStr += ‘<div class="fileWrap">‘; 9 htmlStr += ‘<input type="file" accept="image/gif,image/jpeg,image/jpg,image/png,image/svg" onchange="upImg(this)"/>‘; 10 htmlStr += ‘</div>‘; 11 htmlStr += ‘<div class="imgWrap upedImg"><span class="deleteImg">X</span>‘; 12 htmlStr += ‘<img src="‘+fr.result+‘" />‘; 13 htmlStr += ‘</div>‘; 14 htmlStr += ‘</div>‘; 15 $(‘.imgOnloadWrap‘).append(htmlStr); 16 obj.value = ‘‘; 17 } 18 fr.readAsDataURL(imgFile); 19 }
以上是关于图片预览的主要内容,如果未能解决你的问题,请参考以下文章