Checking HTML5 drag and drop file type

前端 未结 3 692
野趣味
野趣味 2021-02-08 09:52

I\'d like to change drop zone background color to green or red depending on whether the contained drag over payload contains supported file types (JPEG).

  • Do Ge

3条回答
  •  太阳男子
    2021-02-08 10:20

    You can get the file types in Gecko and webkit supported browsers using file object.

    var files =e.dataTransfer.files||e.target.files; // File list
    

    The file object returns Name,Type and size. you can get last modified date too.

    var mimeType= files[0].type; //mime type of file list first entry
    

提交回复
热议问题