有時候我們會在微信公眾號里開發會遇到上傳圖片的功能,當你寫<input type="file"> 的時候,在IOS上可以成功調起拍照和圖庫兩塊,在安卓手機上只能調取圖庫而沒有拍照功能,解決辦法:給input 加上accept屬性
<input type="file" accept="image/*" /> //調用相機 ,圖片或者相冊 (兩者都行)
加上了capture=camera"屬性之后安卓手機就直接調用了相機,沒有了圖庫的選項
<input type="file" accept="image/*;capture=camera"> //直接調用相機
<input type="file" accept="video/*;capture=camcorder"> // 調取視頻
<input type="file" accept="audio/*;capture=microphone"> //調取音頻
注:capture表示,可以捕獲到系統默認的設備,比如:camera--照相機;camcorder--攝像機;microphone--錄音。