您的位置:首页 > Web前端 > HTML5

html5手机 input file 上传图片 调用API

2015-11-11 15:44 591 查看
html代码:

<input type="file" id="file" capture="camera" style="display: none"/>

<img src="add_big.png" width="61px" height="62px" onclick="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/*" />调用相机 图片或者相册
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: