最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - how would I detect if "multiple" attribute is supported for file input elements? - Stack Overflow

programmeradmin3浏览0评论

Internet Explorer does not support the multiple attribute for <input type="file" />. However, its not only IE that lacks this support... also certain mobile browsers do not support the multiple attribute. So simply detecting that the browser is IE is not the ideal solution.

So how would I detect if the multiple attribute is supported for for <input type="file" /> with JavaScript?

UPDATE

It seems like Modernizr has support for new HTML5 input element attributes:

The accepted solution seems to work, however, since I'm already using Modernizr, my solution is the following:

/**
 * Determines if the given attribute is supported for <input /> elements.
 * 
 * @param attribute - the attribute to test for (ex. "multiple")
 */
function isInputAttributeSupported(attribute) {
    return (Modernizr.input[attribute]) ? true : false;
};

Internet Explorer does not support the multiple attribute for <input type="file" />. However, its not only IE that lacks this support... also certain mobile browsers do not support the multiple attribute. So simply detecting that the browser is IE is not the ideal solution.

So how would I detect if the multiple attribute is supported for for <input type="file" /> with JavaScript?

UPDATE

It seems like Modernizr has support for new HTML5 input element attributes:

http://modernizr.com/docs/#input

The accepted solution seems to work, however, since I'm already using Modernizr, my solution is the following:

/**
 * Determines if the given attribute is supported for <input /> elements.
 * 
 * @param attribute - the attribute to test for (ex. "multiple")
 */
function isInputAttributeSupported(attribute) {
    return (Modernizr.input[attribute]) ? true : false;
};
Share Improve this question edited Sep 18, 2012 at 16:49 Hristo asked May 5, 2012 at 0:33 HristoHristo 46.5k67 gold badges168 silver badges234 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 15

You can try checking for the existence of the corresponding property:

var supportsMultipleFiles = 'multiple' in document.createElement('input');

Example: http://jsfiddle.net/sbZvS/

var inp = document.createElement("input");
inp.setAttribute("multiple", "true");
var supportsMultiple = inp.multiple===true;

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论