jQuery实现图片预览功能

 1 /**
 2  * 图片预览
 3  */
 4 function priview(imgShow) {
 5     /*
 6        jquery中的live()方法在jquery1.9及以上的版本中已被废弃了,
 7        如果使用,会抛出TypeError: $(...).live is not a function错误。
      imgShow为为传入对象:例如$('#img')
8 */ 9 imgShow.on('change',function () { 10 //获取文件 11 var file = this.files[0]; 12 //读取文件 13 if (window.FileReader) { 14 var reader = new FileReader(); 15 reader.readAsDataURL(file); 16 //监听文件读取结束后事件 17 reader.onloadend=function (e) { 18 $("#imgShow").attr('src',e.target.result); 19 }; 20 } 21 }) 22 }

 

posted @ 2020-12-01 19:50  donleo123  阅读(860)  评论(0)    收藏  举报