問題描述
我想將拖放區(qū)的背景顏色更改為綠色或紅色,具體取決于包含的拖拽負(fù)載是否包含支持的文件類型 (JPEG).
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).
Gecko 和 Webkit 是否支持確定拖放文件的文件類型?
Do Gecko and Webkit support determining the file type of drag and drop files?
如何在這兩種瀏覽器中提取文件類型?
How one can extract the file type in these two browsers?
我找到了 event.dataTransfer.types API,但對(duì)于 Firefox,它似乎填充了 application/x-moz-file,因此我認(rèn)為我做錯(cuò)了.
I have found event.dataTransfer.types API, but for Firefox it seems to be populated with application/x-moz-file and thus I think I am doing something wrong.
推薦答案
您可以使用文件對(duì)象在 Gecko 和 webkit 支持的瀏覽器中獲取文件類型.
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
文件對(duì)象返回名稱、類型和大小.您也可以獲取上次修改日期.
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
這篇關(guān)于檢查 HTML5 拖放文件類型的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!