兼容安卓和苹果移动端就input调起手机相册和相机

如下这么写的话,苹果手机能够调起相机和相册功能,可是安卓手机只能调起相册;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");   };}

相关文章
相关标签/搜索