我将如何检测“多重”文件输入元素支持属性? [英] how would I detect if "multiple" attribute is supported for file input elements?

查看:130
本文介绍了我将如何检测“多重”文件输入元素支持属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

那么如何检测多个属性支持< input type =file/> 与JavaScript?

UPDATE < h2>

看起来Modernizr支持新的HTML5输入元素属性:

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



接受的解决方案似乎工作,但是,因为我已经使用Modernizr,我的解决方案如下:

  / ** 
*确定给定属性是否支持< input />元素。
*
* @param属性 - 要测试的属性(例如multiple)
* /
函数isInputAttributeSupported(属性){
return(Modernizr。输入[属性])?真假;
};


解决方案

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


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

解决方案

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

这篇关于我将如何检测“多重”文件输入元素支持属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆