移動端H5調用攝像頭(選擇上傳圖片)


<label>照相機</label> <input type="file" id='image' accept="image/*" capture='camera'> <br> <label>攝像機</label> <input type="file" id='video' accept="video/*" capture='camcorder'>

多選:
<input type="file" id="file" multiple>

在各個機型都可以點擊 file 調用相冊 和 攝像頭拍照 
1. 在老版本的安卓中,必須加上capture,否則只能調用相冊 
2. 在IOS中 加了capture,就只能調用攝像頭不能調用相冊

判斷ios,如果是ios就去掉capture屬性.
let info=navigator.userAgent.toLowerCases();
if(info.match(/iPhone\sOS/i)){

  dom.removeAttribute("capture")  

  }

 

讀取圖片(fileChoose即為input)

fileChoose.change=()=>{

  let file=fileChoose.files[0],

  reader=new FileReader();

  reader.onLoad=()=>{

    img.src=reader.result

  };

  reader.readAsDataURL(file)

}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM