input的file一些实用属性

  file自带一些有用的属性,今天整理一下

  html:

  1.multiple:是否多选,如果在html上面写上multiple="multiple"或者multiple就可以实现多选

  2.accept:文件格式,这个可以控制文件格式,比如jpeg和gif还有Png之类的,写法是这样的<input type="file" accept="image/png,image/gif,image/jpeg" />

  js:

  1.name:文件名字,一般写法是这样的

  console.log(img.files[0].name) //img2.jpg

  2.size:选择文件的大小,写法如下

  console.log(img.files[0].size) //15781 

原文地址:https://www.cnblogs.com/myzsy/p/6689486.html