微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

Internet Explorer不支持< input type =“file”/>的多个属性.然而,它不仅缺乏这种支持的IE ……某些移动浏览器也不支持属性.因此,简单地检测浏览器是IE不是理想的解决方案.

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

UPDATE

似乎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 inp = document.createElement("input");
inp.setAttribute("multiple","true");
var supportsMultiple = inp.multiple===true;

原文地址:https://www.jb51.cc/js/159508.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐