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/*" />调用相机 图片或者相册
<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/*" />调用相机 图片或者相册
相关文章推荐
- H5地理定位
- cdh5.4.7 sqoop使用
- Html5_移动前端不得不了解的html5 head 头标签
- html5视频播放解决方案
- HTML5上传图片预览
- HTML5 Web Worker深入浅出教程
- html5 hash
- HTML5中custom data-*特性与asp.net mvc 3 表单验证
- html5
- 基于HTML5树组件延迟加载技术实现
- 基于HTML5树组件延迟加载技术实现
- HTML5音乐播放器效果非常漂亮
- HTML5 Canvas画线技巧
- 移动前端头部标签(HTML5 head meta)
- 可以用来开发h5的软件小结
- HTML5 Viewport Meta Tag
- html5第一章
- html5中关于音频--视频的播放
- 让所有浏览器支持HTML5 video视频标签
- HTML5 LocalStorage本地存储和sessionStorage使用