最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

javascript實現(xiàn)移動端上傳圖片功能

 更新時間:2020年08月18日 11:18:21   作者:wild_guiqulaixi  
這篇文章主要為大家詳細(xì)介紹了javascript實現(xiàn)移動端上傳圖片功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了javascript實現(xiàn)移動端上傳圖片的具體代碼,供大家參考,具體內(nèi)容如下

核心部分(.html)

window.onload = function() {
 let fileTag = document.getElementById('file');
 // console.log(fileTag)
 // console.log(this.pic)
 let that = this
 
 fileTag.onchange = function() {
 let file = fileTag.files[0];
 let fileReader = new FileReader();
 // console.log(file)
 console.log(fileReader)
 // console.log(that.pic)
 fileReader.onloadend = function() {
 console.log(1212)
 if (fileReader.readyState == fileReader.DONE) {
  // console.log(that.pic)
  console.log(fileReader)
  
  if(that.pic=="") {
  console.log(1111)
  that.pic = fileReader.result
  that.input1 = false
  
  that.upLoad(fileReader.result)
  return
  }else{
  if(that.pic2=='') {
  console.log(2222)
  that.pic2 = fileReader.result
  that.input2 = false
  return
  }else {
  if(that.pic3=='') {
  console.log(3333)
  that.pic3 = fileReader.result
  that.input3 = false
  return
  }else {
  if(that.pic4=='') {
   console.log(4444)
   that.pic4 = fileReader.result
   that.input4 = false
   return
  }else {
   console.log(5555)
   if(that.pic5=='') {
   that.pic5 = fileReader.result
   that.input5 = false
   return
   }
   
  }
  }
  }
  
  }
  // console.log(that.pic)
 }
 };
 
 fileReader.readAsDataURL(file);
 }
} 

vue項目代碼

主要是HTML頁面設(shè)計

<div class="imgBox" @click="upImg">
 <div style="display:flex;flex-flow:wrap;">
 <div class="Img" >
 <label>
 <img v-if="pic==''" src="./img/addPhotos.jpg">
 <img v-else width='100%' height='100%' style="border-radius:5px" id="img" :src="pic">
 <input v-if="input1" class="myInput" type="file" id="file" accept="image/*" multiple required>
 </label>
 <div v-if="pic!=''" class="myDel" @click="delImg(1)">X</div>
 
 </div>
 <div class="Img" v-if="pic!='' || !input2">
 <label>
 <img v-if="pic2==''" src="./img/addPhotos.jpg">
 <img v-else width='100%' height='100%' style="border-radius:5px" :src="pic2">
 <input v-if="input2" class="myInput" type="file" id="file" accept="image/*" multiple required>
 </label>
 <div v-if="pic2!=''" class="myDel" @click="delImg(2)">X</div>
 </div>
 <div class="Img" v-if="(pic!='' && pic2!='' ) || !input3">
 <label>
 <img v-if="pic3==''" src="./img/addPhotos.jpg">
 <img v-else width='100%' height='100%' style="border-radius:5px" :src="pic3">
 <input v-if="input3" class="myInput" type="file" id="file" accept="image/*" multiple required>
 </label>
 <div v-if="pic3!=''" class="myDel" @click="delImg(3)">X</div>
 </div>
 <div class="Img" v-if="(pic!='' && pic2!='' && pic3!='') || !input4">
 <label>
 <img v-if="pic4==''" src="./img/addPhotos.jpg">
 <img v-else width='100%' height='100%' style="border-radius:5px" :src="pic4">
 <input v-if="input4" class="myInput" type="file" id="file" accept="image/*" multiple required>
 </label>
 <div v-if="pic4!=''" class="myDel" @click="delImg(4)">X</div>
 </div>
 <div class="Img" v-if="(pic!='' && pic2!='' && pic3!='' && pic4!='') || !input5">
 <label> 
 <img v-if="pic5==''" src="./img/addPhotos.jpg">
 <img v-else width='100%' height='100%' style="border-radius:5px" :src="pic5">
 <input v-if="input5" class="myInput" type="file" id="file" accept="image/*" multiple required>
 </label>
 <div v-if="pic5!=''" class="myDel" @click="delImg(5)">X</div>
 </div>
 </div>
</div>

data()部分

pic:'',
pic2:'',
pic3:'',
pic4:'',
pic5:'',
input1:true,
input2:true,
input3:true,
input4:true,
input5:true

methods:{}部分

upImg() {
 
 // window.onload = function() {
 let fileTag = document.getElementById('file');
 // console.log(fileTag)
 // console.log(this.pic)
 let that = this
 
 fileTag.onchange = function() {
 let file = fileTag.files[0];
 let fileReader = new FileReader();
 // console.log(file)
 console.log(fileReader)
 // console.log(that.pic)
 fileReader.onloadend = function() {
 console.log(1212)
 if (fileReader.readyState == fileReader.DONE) {
  // console.log(that.pic)
  console.log(fileReader)
  
  if(that.pic=="") {
  console.log(1111)
  that.pic = fileReader.result
  that.input1 = false
  
  that.upLoad(fileReader.result)
  return
  }else{
  if(that.pic2=='') {
  console.log(2222)
  that.pic2 = fileReader.result
  that.input2 = false
  return
  }else {
  if(that.pic3=='') {
  console.log(3333)
  that.pic3 = fileReader.result
  that.input3 = false
  return
  }else {
  if(that.pic4=='') {
   console.log(4444)
   that.pic4 = fileReader.result
   that.input4 = false
   return
  }else {
   console.log(5555)
   if(that.pic5=='') {
   that.pic5 = fileReader.result
   that.input5 = false
   return
   }
  }
  }
  }
  }
  // console.log(that.pic)
 }
 };
 fileReader.readAsDataURL(file);
 }
 // } 
},
delImg(num) {
 if(num==1) {
 this.pic = ''
 this.input1 = true
 }
 if(num==2) {
 this.pic2 = ''
 this.input2 = true
 }
 if(num==3) {
 this.pic3 = ''
 this.input3 = true
 }
 if(num==4) {
 this.pic4 = ''
 this.input4 = true
 }
 if(num==5) {
 this.pic5 = ''
 this.input5 = true
 }
}

css部分(style)

#order .imgBox {
 margin-bottom: 100px;
 padding: 20px;
 box-sizing: border-box;
 background: #fff;
 height: 250px;
}

#order .Img {
 width: 90px;
 height: 90px;
 background: #fff;
 text-align: center;
 line-height: 132px;
 box-sizing: border-box;
 border-radius: 5px;
 border: 1px solid rgba(0,0,0,.2);
 position: relative;
 margin: 0 20px 20px 0;
}

#order .myInput {
 opacity:0;
 position:absolute;
 top:0;
 top:0;
 width:90px;
 height:90px;
 left:0;
}

#order .myDel {
 color: #fff;
 position: absolute;
 right: -10px;
 top: -7px;
 width: 25px;
 height: 25px;
 border-radius: 25px;
 line-height: 25px;
 background: rgba(0,0,0,.5);
}

效果圖

更多精彩內(nèi)容請參考專題《ajax上傳技術(shù)匯總》,《javascript文件上傳操作匯總》《jQuery上傳操作匯總》進(jìn)行學(xué)習(xí)。

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • js實現(xiàn)簡單點贊操作

    js實現(xiàn)簡單點贊操作

    這篇文章主要為大家詳細(xì)介紹了js實現(xiàn)簡單點贊操作,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-03-03
  • 微信小程序與webview交互實現(xiàn)支付功能

    微信小程序與webview交互實現(xiàn)支付功能

    這篇文章主要介紹了微信小程序與webview交互實現(xiàn)支付功能,文中通過示例代碼介紹的非常詳細(xì),對大家學(xué)習(xí)或者使用小程序具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-06-06
  • JavaScript語法 JSON序列化之stringify實例詳解

    JavaScript語法 JSON序列化之stringify實例詳解

    這篇文章主要為大家介紹了JavaScript語法 JSON序列化之stringify實例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-10-10
  • JS比較2個日期間隔的示例代碼

    JS比較2個日期間隔的示例代碼

    這篇文章主要介紹了JS比較2個日期間隔的方法,需要的朋友可以參考下
    2014-04-04
  • javascript數(shù)組去重的六種方法匯總

    javascript數(shù)組去重的六種方法匯總

    數(shù)組去重復(fù)是一個常見的需求,我們暫時考慮同類型的數(shù)組去重復(fù)。主要是理清思路和考慮下性能。以下方法,有各人總結(jié)也有網(wǎng)上熱心網(wǎng)友的方法,這里簡單地總結(jié)一下。
    2015-08-08
  • js 判斷字符串中是否包含某個字符串的實現(xiàn)代碼

    js 判斷字符串中是否包含某個字符串的實現(xiàn)代碼

    工作中經(jīng)常會使用到判斷一個字符串是否包含某一個字符串,因此總結(jié)一下幾個方法,需要的朋友可以參考下
    2023-03-03
  • js實現(xiàn)讓某個動作延遲幾秒執(zhí)行

    js實現(xiàn)讓某個動作延遲幾秒執(zhí)行

    這篇文章主要介紹了使用js實現(xiàn)讓某個動作延遲幾秒執(zhí)行的方法,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-06-06
  • layui清空,重置表單數(shù)據(jù)的實例

    layui清空,重置表單數(shù)據(jù)的實例

    今天小編就為大家分享一篇layui清空,重置表單數(shù)據(jù)的實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-09-09
  • 微信小程序 rich-text的使用方法

    微信小程序 rich-text的使用方法

    這篇文章主要介紹了 微信小程序 rich-text的使用方法的相關(guān)資料,這里提供屬性及方法并實現(xiàn)實例,幫助大家學(xué)習(xí)理解,需要的朋友可以參考下
    2017-08-08
  • 完美實現(xiàn)js選項卡切換效果(二)

    完美實現(xiàn)js選項卡切換效果(二)

    這篇文章主要為大家詳細(xì)介紹如何完美實現(xiàn)js選項卡切換效果,通過設(shè)置定時器實現(xiàn)延時0.5s切換選項卡,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-03-03

最新評論

漠河县| 长沙县| 晋城| 富蕴县| 林州市| 玛纳斯县| 双辽市| 广德县| 疏勒县| 根河市| 西和县| 石柱| 宝清县| 四平市| 苏尼特右旗| 都安| 卢氏县| 绵竹市| 西充县| 电白县| 博罗县| 无锡市| 白城市| 晋州市| 神池县| 长阳| 巧家县| 应城市| 孙吴县| 大同市| 华池县| 广宁县| 巴楚县| 双流县| 河曲县| 南康市| 固原市| 桐庐县| 鲁甸县| 桃园市| 太康县|