jquery.support用于检测JavaScript的File API?

我无法通过jQuery中的.support方法找到检测浏览器是否支持File API的方法。

谁知道呢?

(顺便提一下:用IE检测input[type=file]文件大小的方法?)

它似乎没有在jQuery中实现,但你可以检查自己: http : //jsfiddle.net/pimvdb/RCz3s/ 。

files属性如果已实现则返回空FileList ,否则未定义(即undefined )。

 var support = (function(undefined) { return $("") // create test element .get(0) // get native element .files !== undefined; // check whether files property is not undefined })(); 

另一种检查方法是检查File API类型的存在:

 var FileApiSupported = !!('File' in window && 'FileReader' in window && 'FileList' in window && 'Blob' in window);