以下這么寫的話,蘋果手機可以調起相機和相冊功能,但是安卓手機只能調起相冊;
<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">
而這么寫的話,可以讓安卓手機同時調起相機和相冊,但是,蘋果手機卻只能調起相機:
<input id="upLicense" onchange="preview(this,0)" type="file" name="upLicense" accept="image/*" capture="camera" multiple>
所以,綜上結合,可以在一開始的時候這么寫:
<input id="upLicense" onchange="preview(this,0)" type="file" name="upLicense" accept="image/*" capture="camera" multiple>
然后在頁面js中這么寫:
$(function()){
compatibleInput();
}
// 判斷當前是否屬於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");
};
}