Checking HTML5 drag and drop file type(检查 HTML5 拖放文件类型)
问题描述
我想将拖放区的背景颜色更改为绿色或红色,具体取决于包含的拖拽负载是否包含支持的文件类型 (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,但对于 Firefox,它似乎填充了 application/x-moz-file,因此我认为我做错了.
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.
推荐答案
您可以使用文件对象在 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
文件对象返回名称、类型和大小.您也可以获取上次修改日期.
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
这篇关于检查 HTML5 拖放文件类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:检查 HTML5 拖放文件类型


基础教程推荐
- 即使用户允许,Gmail 也会隐藏外部电子邮件图片 2022-01-01
- Fabric JS绘制具有活动形状的多边形 2022-01-01
- Bootstrap 模态出现在背景下 2022-01-01
- npm start 错误与 create-react-app 2022-01-01
- fetch 是否支持原生多文件上传? 2022-01-01
- 原生拖动事件后如何获取 mouseup 事件? 2022-01-01
- Bokeh Div文本对齐 2022-01-01
- 检查 HTML5 拖放文件类型 2022-01-01
- 在 contenteditable 中精确拖放 2022-01-01
- 如何添加到目前为止的天数? 2022-01-01