javascript实现移动端上传图片功能
本文实例为大家分享了javascript实现移动端上传图片的具体代码,供大家参考,具体内容如下
核心部分(.html)
window.onload=function(){ letfileTag=document.getElementById('file'); //console.log(fileTag) //console.log(this.http://www.haoziyuan.ccpic) letthat=this fileTag.onchange=function(){ letfile=fileTag.files[0]; letfileReader=newFileReader(); //console.log(file) console.log(fileReader) //console.log(that.http://www.haoziyuan.ccpic) fileReader.onloadend=function(){ console.log(1212) if(fileReader.readyState==fileReader.DONE){ //console.log(that.http://www.haoziyuan.ccpic) console.log(fileReader) if(that.http://www.haoziyuan.ccpic==""){ console.log(1111) that.http://www.haoziyuan.ccpic=fileReader.result that.input1=false that.upLoad(fileReader.result) return }else{ if(that.http://www.haoziyuan.cchttp://www.haoziyuan.ccpic2==''){ console.log(2222) that.http://www.haoziyuan.cchttp://www.haoziyuan.ccpic2=fileReader.result that.input2=false return }else{ if(that.http://www.haoziyuan.cchttp://www.haoziyuan.ccpic3==''){ console.log(3333) that.http://www.haoziyuan.cchttp://www.haoziyuan.ccpic3=fileReader.result that.input3=false return }else{ if(that.http://www.haoziyuan.cchttp://www.haoziyuan.ccpic4==''){ console.log(4444) that.http://www.haoziyuan.cchttp://www.haoziyuan.ccpic4=fileReader.result that.input4=false return }else{ console.log(5555) if(that.http://www.haoziyuan.cchttp://www.haoziyuan.ccpic5==''){ that.http://www.haoziyuan.cchttp://www.haoziyuan.ccpic5=fileReader.result that.input5=false return } } } } } //console.log(that.http://www.haoziyuan.ccpic) } }; fileReader.readAsDataURL(file); } }
vue项目代码
主要是HTML页面设计
X