jQuery实现图片预览功能 电脑版发表于:2022/9/30 10:10 ``` /** * 图片预览 */ function priview(imgShow) { /* jquery中的live()方法在jquery1.9及以上的版本中已被废弃了, 如果使用,会抛出TypeError: $(...).live is not a function错误。 imgShow为为传入对象:例如$('#img') */ imgShow.on('change',function () { //获取文件 var file = this.files[0]; //读取文件 if (window.FileReader) { var reader = new FileReader(); reader.readAsDataURL(file); //监听文件读取结束后事件 reader.onloadend=function (e) { $("#imgShow").attr('src',e.target.result); }; } }) } ```