4

我想检测(使用 javascript/jQuery)用户的浏览器是否支持multiple属性input type='file'标记。HTML5 添加多个图像的功能。

<input type=file  name="images" value=" " multiple=""/>

请建议我该怎么做。

4

5 回答 5

6
var i = document.createElement("input");
if (typeof i.multiple !== 'undefined') {
    // supports multiple
}
于 2012-05-05T13:23:44.147 回答
2

您可以使用modernizr为此目的开发的。

http://modernizr.com/

您可以通过placeholder以下方式检测对功能的支持:

if (!Modernizr.input.placeholder) {

}
于 2012-05-05T13:21:26.507 回答
1

从 Modernizr 来源获取和编辑:

var inputElem = document.createElement('input');
var multipleSupport = !!(multiple in inputElem);

如果这是您唯一需要的,则不需要包含完整的库。

于 2012-05-05T13:26:32.210 回答
0

我建议你使用 Modernizr javascript 库?这提供了一种检查浏览器是否支持各种功能的方法。

于 2012-05-05T13:21:39.943 回答
0

您可以使用Modernizr,它会为您进行大量此类测试。

但是,在这种情况下,测试非常简单:

if (typeof document.createElement('input').multiple !== "undefined") {
    // ... yes, it has it
}

元素上的所有其他新属性也是如此。

于 2012-05-05T13:26:21.367 回答