gpt4 book ai didi

javascript - 我如何检测文件输入元素是否支持 "multiple"属性?

转载 作者:太空狗 更新时间:2023-10-29 13:35:43 24 4
gpt4 key购买 nike

Internet Explorer 不支持 multiple <input type="file" /> 的属性.然而,不只是 IE 缺乏这种支持……某些移动浏览器也不支持 multiple属性。所以简单地检测浏览器是IE并不是理想的解决方案。

那么我如何检测 multiple <input type="file" /> 支持属性用 JavaScript?

更新

Modernizr 似乎支持新的 HTML5 输入元素属性:

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

公认的解决方案似乎有效,但是,由于我已经在使用 Modernizr,我的解决方案如下:

/**
* 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;
};

最佳答案

您可以尝试检查相应属性是否存在:

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

示例:http://jsfiddle.net/sbZvS/

关于javascript - 我如何检测文件输入元素是否支持 "multiple"属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10457770/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com