在此做一个笔记

<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 文件上传(照片,视频,音频)的更多相关文章

  1. js 实现 input file 文件上传

    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat=&qu ...

  2. input file 文件上传标签的样式美化

    input file 文件上传标签的样式美化 将<input type="file">的透明度设置为0: <input type="file" ...

  3. input file 文件上传,js控制上传文件的大小和格式

    文件上传一般是用jquery的uploadify,比较好用.后面会出文章介绍uploadify这个插件. 但是,有时候为了偷懒,直接就用input 的file进行文件和图片等的上传,input fil ...

  4. 修改input file 文件上传的样式

    Web页面中,在需要上传文件时基本都会用到<input type="file">元素,它的默认样式: chrome下: IE下: 不管是上面哪种,样式都比较简单,和很多 ...

  5. PHP 多input file文件上传

    前台html jquery代码 后台PHP处理 前台html <form id="form" method="post" enctype="mu ...

  6. input file文件上传样式

    <style>    .file-group {        position: relative;        width: 200px;        height: 80px;  ...

  7. js 实现 input type="file" 文件上传示例代码

    在开发中,文件上传必不可少但是它长得又丑.浏览的字样不能换,一般会让其隐藏点其他的标签(图片等)来时实现选择文件上传功能 在开发中,文件上传必不可少,<input type="file ...

  8. [置顶] js 实现 <input type="file" /> 文件上传

    在开发中,文件上传必不可少,<input type="file" /> 是常用的上传标签,但是它长得又丑.浏览的字样不能换,我们一般会用让,<input type ...

  9. input实现文件上传

    input实现文件上传 input + ajax 实现文件上传,包括文件大小及类型的判断 一.html <input type="file" id="file&qu ...

  10. js插件---IUpload文件上传插件(包括图片)

    js插件---IUpload文件上传插件(包括图片) 一.总结 一句话总结:上传插件找到真正上传位置的代码,这样就可以知道整个上传插件的逻辑了, 找资料还是github+官方 1.如何在js中找到真正 ...

随机推荐

  1. 基于Centos7.2使用Cobbler工具定制化批量安装Centos7.2系统

    1.1    定制Centos_7_x86_64.ks文件内容 # Cobbler for Kickstart Configurator for CentOS 7.2.1511 by Wolf_Dre ...

  2. windows server 服务器 环境配置

    自动备份 xcopy d:\web\zhiku\*.* d:\bak\web\zhiku\%date:~,4%%date:~5,2%%date:~8,2%\ /S /I

  3. 图解Disruptor框架(二):核心概念

    图解Disruptor框架(二):核心概念 概述 上一个章节简单的介绍了了下Disruptor,这节就是要好好的理清楚Disruptor中的核心的概念.并且会给出个HelloWorld的小例子. 在正 ...

  4. Python全栈之jQuery笔记

    jQuery runnoob网址: http://www.runoob.com/jquery/jquery-tutorial.html jQuery API手册: http://www.runoob. ...

  5. leetcode-22-string

    521. Longest Uncommon Subsequence I find the longest uncommon subsequence of this group of two strin ...

  6. python multiprocessing 源码分析

    1. 文档是最先需要了解的,读完文档可能会有很多的意外的收获同时也会留下疑惑,对于一般的使用我觉得读完文档就差不多了,除非一些很有疑惑的地方你可能需要再深入的了解一下.我读文档的目的第一个就是为了找出 ...

  7. luogu1742 最小圆覆盖

    狗题卡我精度--sol #include <algorithm> #include <iostream> #include <cstdlib> #include & ...

  8. Linux中 find 常见用法示例

    Linux中find常见用法示例 #find path -option [ -print ] [ -exec -ok command ] {} \; #-print 将查找到的文件输出到标准输出 #- ...

  9. 使用MySQLWorkBench连接数据库

    在日常使用中,经常使用命令行去连接MySQL数据库不方便,推荐使用MySQLWorkBench去远程连接进行管理,下面记录一下使用步骤: 1. 安装MySQLWorkBench后,界面如下,点击“+” ...

  10. java EE技术体系——CLF平台API开发注意事项(3)——API安全访问控制

    前言:提离职了,嗯,这么多年了,真到了提离职的时候,心情真的很复杂.好吧,离职阶段需要把一些项目中的情况说明白讲清楚,这篇博客就简单说一下在平台中对API所做的安全处理(后面讲网关还要说,这里主要讲代 ...