js-input file 文件上传(照片,视频,音频)
在此做一个笔记
<input type="file" accept="image/*" capture="camera">
<input type="file" accept="video/*" capture="camcorder">
<input type="file" accept="audio/*" capture="microphone">
accept表示打开的系统文件目录;
capture表示的是系统所捕获的默认设备(camera:照相机;camcorder:摄像机;microphone:录音);
multiple:支持多选,当支持多选时,multiple优先级大于capture;
再我做的一个红包活动中,需要笑脸照片来判断发红包,所以用到了input type="file"的标签属性,本来用的capture="camera"直接拍照,但是在ios上调相机是没有美颜功能的,担心用户不会选择上传,所以之后改变策略了,用了multiple,就是这样;
我的源代码:
<img src="" class="closebtnimg" id="closeimg1" /> //该标签是要放上传的照片的哈
<input type="file" accept="image/*" multiple class="img" onchange="javascript:setImagePreview('addimg1','closeimg1');" id="addimg1" />(错误的,有些手机不支持,底部有更新的正确的写法)
js:
var docObj;
function setImagePreview(btnfile, imgId) {
docObj = document.getElementById(btnfile);
var imgObjPreview = document.getElementById(imgId);
if (docObj.files && docObj.files[0]) {
imgObjPreview.style.display = 'block';
imgObjPreview.style.width = '100%';
imgObjPreview.src = window.URL.createObjectURL(docObj.files[0]);
} else {
imgObjPreview.style.display = 'block';
}
return true;
}
以上是我的代码,很完美的哈,经过测试验证的。
2018-7-11更新调整
本来以上的代码是ok的,但是后期我用了大量的手机测试,有些手机是不成功的,所以上面的Html更新为最新的:
<input type="file" accept="image/*" class="img" onchange="javascript:setImagePreview('addimg1','closeimg1');" id="addimg1" /> (正确的,所有手机支持选择拍照,照片)
js-input file 文件上传(照片,视频,音频)的更多相关文章
- js 实现 input file 文件上传
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat=&qu ...
- input file 文件上传标签的样式美化
input file 文件上传标签的样式美化 将<input type="file">的透明度设置为0: <input type="file" ...
- input file 文件上传,js控制上传文件的大小和格式
文件上传一般是用jquery的uploadify,比较好用.后面会出文章介绍uploadify这个插件. 但是,有时候为了偷懒,直接就用input 的file进行文件和图片等的上传,input fil ...
- 修改input file 文件上传的样式
Web页面中,在需要上传文件时基本都会用到<input type="file">元素,它的默认样式: chrome下: IE下: 不管是上面哪种,样式都比较简单,和很多 ...
- PHP 多input file文件上传
前台html jquery代码 后台PHP处理 前台html <form id="form" method="post" enctype="mu ...
- input file文件上传样式
<style> .file-group { position: relative; width: 200px; height: 80px; ...
- js 实现 input type="file" 文件上传示例代码
在开发中,文件上传必不可少但是它长得又丑.浏览的字样不能换,一般会让其隐藏点其他的标签(图片等)来时实现选择文件上传功能 在开发中,文件上传必不可少,<input type="file ...
- [置顶] js 实现 <input type="file" /> 文件上传
在开发中,文件上传必不可少,<input type="file" /> 是常用的上传标签,但是它长得又丑.浏览的字样不能换,我们一般会用让,<input type ...
- input实现文件上传
input实现文件上传 input + ajax 实现文件上传,包括文件大小及类型的判断 一.html <input type="file" id="file&qu ...
- js插件---IUpload文件上传插件(包括图片)
js插件---IUpload文件上传插件(包括图片) 一.总结 一句话总结:上传插件找到真正上传位置的代码,这样就可以知道整个上传插件的逻辑了, 找资料还是github+官方 1.如何在js中找到真正 ...
随机推荐
- 【jquery】 form ajaxSubmit 问题
常见问题 这个插件跟哪些版本的jQuery兼容? 这个插件需要jQuery v1.0.3 或 以后的版本. 这个插件需要其它插件的支持吗? 不需要. 这个插件的运行效率高吗? 是的!请到 对比页面 查 ...
- navigationcontroller和navigationbar和navigationitem之间的区别以及不用nib实现点击屏幕关闭虚拟键盘20130911
1.UIViewController UIView的关系. UIView是视图,UIViewController是视图控制器,两者之间是从属关系,当创建一个UIViewController的时候,一般 ...
- DP刷题记录(长期更新)
bzoj 2748 一个吉他手,有一个初始音量,有一个音量最大值max. 给定n个音量变化量,从第一个变化量开始,可以选择加上或者减去变化量.途中音量不能低于0,不能超过max. 求最后能达到的最大音 ...
- Linux优化总结
1)netstat (*****)查看网络状态lntup或an 1.[listening|-l] 2.[--numeric|-n] 3.[--tcp|-t] 4.[--udp|-u] 5[--prog ...
- 重新造轮子之静态链接1(Static linking)
最近学习计算机病毒学的过程中,又讲到了静态链接的问题,联想到了之前保健哥在信息安全的课堂上向我们展示了一个没有main()函数的C程序到底应该如何编写.个人觉得这个小实验对于加深静态链接的过程的理解也 ...
- HDU 2460 Network 边双连通分量 缩点
题意: 给出一个无向连通图,有\(m\)次操作,每次在\(u, v\)之间加一条边,并输出此时图中桥的个数. 分析: 先找出边双连通分量然后缩点得到一棵树,树上的每条边都输原图中的桥,因此此时桥的个数 ...
- 再谈H2的MVStore与MVMap
对H2的[MVStore]: http://www.cnblogs.com/simoncook/p/5188105.html 这篇文章的补充. 概述 我们通常用的map,比如HashMap Linke ...
- 浅析win32 Win64 x86 x64 区别 及Eclipse启动报Java was started but returned exit code=13 错误
win32.x86_64是64位 X86就是 32位系统 X64 就是64位系统 最好记得方法就是带有64的就是64位,其余都是32位 为什么要讲这个呢? 如果是绿色版本的eclipse,在打开ec ...
- TOJ4277: Sequence 组合数学
4277: Sequence Time Limit(Common/Java):2000MS/6000MS Memory Limit:65536KByte Total Submit: 39 ...
- rails提供的validators
Instance Public methods attribute_method?(attribute)Link Returns true if attribute is an attribute m ...