检查HTML5拖放文件类型 [英] Checking HTML5 drag and drop file type

查看:162
本文介绍了检查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拖放文件类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆