使用accept属性

  1. <input id="file" type="file" accept="image/png,image/gif" name="file" />

常用文件类型

  1. *.3gpp audio/3gpp, video/3gpp
  2. *.ac3 audio/ac3
  3. *.asf allpication/vnd.ms-asf
  4. *.au audio/basic
  5. *.css text/css
  6. *.csv text/csv
  7. *.doc application/msword
  8. *.dot application/msword
  9. *.dtd application/xml-dtd
  10. *.dwg image/vnd.dwg
  11. *.dxf image/vnd.dxf
  12. *.gif image/gif
  13. *.htm text/html
  14. *.html text/html
  15. *.jp2 image/jp2
  16. *.jpe image/jpeg
  17. *.jpeg image/jpeg
  18. *.jpg image/jpeg
  19. *.js text/javascript, application/javascript
  20. *.json application/json
  21. *.mp2 audio/mpeg, video/mpeg
  22. *.mp3 audio/mpeg
  23. *.mp4 audio/mp4, video/mp4
  24. *.mpeg video/mpeg
  25. *.mpg video/mpeg
  26. *.mpp application/vnd.ms-project
  27. *.ogg application/ogg, audio/ogg
  28. *.pdf application/pdf
  29. *.png image/png
  30. *.pot application/vnd.ms-powerpoint
  31. *.pps application/vnd.ms-powerpoint
  32. *.ppt application/vnd.ms-powerpoint
  33. *.rtf application/rtf, text/rtf
  34. *.svf image/vnd.svf
  35. *.tif image/tiff
  36. *.tiff image/tiff
  37. *.txt text/plain
  38. *.wdb application/vnd.ms-works
  39. *.wps application/vnd.ms-works
  40. *.xhtml application/xhtml+xml
  41. *.xlc application/vnd.ms-excel
  42. *.xlm application/vnd.ms-excel
  43. *.xls application/vnd.ms-excel
  44. *.xlt application/vnd.ms-excel
  45. *.xlw application/vnd.ms-excel
  46. *.xml text/xml, application/xml
  47. *.zip aplication/zip
  48. *.xlsx application/vnd.openxmlformats-officedocument.spreadsheetml.sheet