文件上传input 属性
<input name="myFile" change="toBase64($event) type="file">
对应事件:change
常用属性:accept, multiple, capture
accept:限制文件类型
audio/* 表示所有音频文件 HTML5(支持)
video/* 表示视频文件 HTML5(支持)
image/* 表示图片文件 HTML5(支持)
支持逗号分隔的 MIME 类型字符串,写可以写成如下的方式:
accept="image/png" 或者 accept=".png" ,只接受 png 图片。
accept="image/png, image/jpeg" 或者 accept=".png, .jpg, .jpeg" ,接受 PNG 和 JPEG 文件。
accept="image/*" ,接受任何图片文件类型。
multiple(多选):
multiple 属性:当用户所在的平台允许使用 Shift 或者 Contro键时,用户可以选择多个文件。
如果不希望多选,可以直接忽略 multiple 属性。
capture(调用设备媒体):
capture 属性:在webapp上使用 input 的 file 属性,指定 capture 属性可以调用系统默认相机、摄像和录音功能。
capture表示,可以捕获到系统默认设备的媒体信息,如下:
capture="camera" 相机
capture="camcorder" 摄像机
capture="microphone" 录音
文件类型限制可选项:
For CSV files (.csv), use:
<input type="file" accept=".csv" />
For Excel Files 2003-2007 (.xls), use:
<input type="file" accept="application/vnd.ms-excel" />
For Excel Files 2010 (.xlsx), use:
<input type="file" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" />
For Text Files (.txt) use:
<input type="file" accept="text/plain" />
For Image Files (.png/.jpg/etc), use:
<input type="file" accept="image/*" />
For HTML Files (.htm,.html), use:
<input type="file" accept="text/html" />
For Video Files (.avi, .mpg, .mpeg, .mp4), use:
<input type="file" accept="video/*" />
For Audio Files (.mp3, .wav, etc), use:
<input type="file" accept="audio/*" />
For PDF Files, use:
<input type="file" accept=".pdf" />