如下這麼寫的話,蘋果手機能夠調起相機和相冊功能,可是安卓手機只能調起相冊;ios
<input id="upLicense" onchange="preview(this,0)" type="file" name="upLicense" >瀏覽器
<input id="upLicense" onchange="preview(this,0)" type="file" name="upLicense" accept="image/*" capture="camera">iphone
而這麼寫的話,可讓安卓手機同時調起相機和相冊,可是,蘋果手機卻只能調起相機:this
<input id="upLicense" onchange="preview(this,0)" type="file" name="upLicense" accept="image/*" capture="camera" multiple>ip
因此,綜上結合,能夠在一開始的時候這麼寫:rem
<input id="upLicense" onchange="preview(this,0)" type="file" name="upLicense" accept="image/*" capture="camera" multiple>input
而後在頁面js中這麼寫:io
$(function()){function
compatibleInput();file
}
// 判斷當前是否屬於ios移動端,兼容input同時調用手機相冊和相機
function compatibleInput(){ //獲取瀏覽器的userAgent,並轉化爲小寫 var ua = navigator.userAgent.toLowerCase(); //判斷是不是蘋果手機,是則是true var isIos = (ua.indexOf('iphone') != -1) || (ua.indexOf('ipad') != -1); if (isIos) { $("input:file").removeAttr("capture"); };}