美文网首页前端行者
input[type=file]属性

input[type=file]属性

作者: 是ADI呀 | 来源:发表于2017-08-28 16:59 被阅读32次

title: input[type=file]属性
date: 2017年8月11日 21:04:48
tags: html
categories: 教程
author: "JiaWei"


** input[type=file] ** 控件用来上传文件。当使用控件时,就授权了网页和服务器访问对应的文件,就可以得到File对象。

在Android手机webview中,是不支持上传文件的,网上说是修改Android端的代码导致的。

  1. accept属性
    该属性表明了服务器端可接受的文件类型,可以限制你手机选择相关的文件,如果限制多个,可以用逗号分割,下面的代码就表示只能选择图片与音频相关的文件:<input accept="image/*,audio/*" type="file"/>
属性值
  1. change事件
    当用户点击控件上传文件会触发change事件,在移动端点击控件时会弹出键盘,体验非常不友好,通过设置属性onfocus="this.blur()"使其失去焦点
    <input type="file" id="upload" onfocus="this.blur()"/>

  2. file对象
    用户所选择的文件都存储在了一个FileList对象上,其中每个文件都对应了一个File对象
    file对象一共由9个属性 获取上次修改的时间file[0].lastModifiedDate) 获取文件名file[0].name 获取大小file[0].size 获取类型file[0].type

  3. 参考资料:
    http://www.cnblogs.com/strick/p/5181701.html 移动端图片操作(一)
    https://developer.mozilla.org/zh-CN/docs/Using_files_from_web_applications 在web应用中使用文件
    http://javascript.ruanyifeng.com/htmlapi/file.html 文件和二进制数据的操作http://www.iunbug.com/archives/2012/06/04/208.html [译]JavaScript文件操作基础
    http://www.iunbug.com/archives/2012/06/05/254.html [译]JavaScript文件操作URL对象http://www.html5rocks.com/zh/tutorials/file/dndfiles 通过 File API 使用 JavaScript 读取文件

相关文章

  • input[type=file]属性

    title: input[type=file]属性date: 2017年8月11日 21:04:48tags: h...

  • 2018-05-04 日常问题总结:

    1.如何去除input默认属性:outline:none; 2.input type=file 用于上传图片, 3...

  • input中属性及作用

    input中属性及作用: 1、accept:指示文件传输的 MIME 类型 ,配合type="file"使...

  • 奇淫巧技

    input type=file 手机浏览器打开相机 input 元素type=file时 ios内核浏览器默认事件...

  • 2019-10-20

    HTML5 File API 在 HTML5 的 input 标签中,新增了一个 type=file 属性的表单控...

  • 前端实现图片上传预览转换base64

    前端实现文件的上传,就必须用到input标签,type属性为file。在vue项目中通ref操作dom。input...

  • blog编写

    title: input[type=file]属性date: 2017年7月31日 12:18:15tags: h...

  • 文件上传

    打开相册: accept 属性只能与 配合使用 它规定能够通过文件上传...

  • Q1:上传文件A以后, 再次上传文件A,不会触发onChange 。 onChange 触发的原理:系统会比较前后...

  • React使用react-cropper实现图片裁剪上传

    用到的组件 实现图片裁切并上传, 本文用到了: html input标签的type=file属性 react-cr...

网友评论

    本文标题:input[type=file]属性

    本文链接:https://www.haomeiwen.com/subject/koygdxtx.html