input file 上传问题

<input  type="file" accept=".png,jpg" multiple="multiple"/>

由于input type=file 样式太过丑陋,一般常用都是用<div>选择上传</div>覆盖原有的input,同时把input定位到div上面,透明度设为0,就可以达到以假乱真。

accept: 接收上传的文件的类型

multiple: 是否支持多文件上传,

name: 一般配合form表单使用

点击上传文件后,一般文件存在e.target.files[0](通过onchange事件)

let formData = new FromData();

formData.append('后台定义接受的字段', e.target.files[0]);

猜你喜欢

转载自www.cnblogs.com/sjw0802/p/9232798.html