html代码:
<input type="file" id="file" capture="camera" style="display: none"/>
<img src="add_big.png" width="61px" height="62px" οnclick="chooseImage()"/> <!--上传图片的按钮-->
js代码:
function chooseImage(){
//判断ios版本
// function gt_ios4() {
//navigator.userAgent = "Mozilla/5.0 (iPhone; U; CPU iPhone OS 6_1_1 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8H7 Safari/6533.18.5";
//alert(navigator.userAgent);
// 判断是否 iPhone 或者 iPod
if((navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPod/i))) {
// 判断系统版本号是否大于 4
if(Boolean(navigator.userAgent.match(/OS [6]_\d[_\d]* like Mac OS X/i))){
alert("您的IOS手机版本低,暂不支持图片上传,请升级到IOS7及以上系统。");
return;
}
}
$("#file").click();
// }
}
也可以
<input type="file" accept="video/*;capture=camcorder">
<input type="file" accept="audio/*;capture=microphone">
<input type="file" accept="image/*;capture=camera">直接调用相机
<input type="file" accept="image/*" />调用相机 图片或者相册