質問

I want to detect (using javascript/jQuery) whether the user's browser supports multiple attribute to input type='file' tag. A feature of HTML5 to add multiple images.

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

Please suggest me how can i do this.

役に立ちましたか?

解決

var i = document.createElement("input");
if (typeof i.multiple !== 'undefined') {
    // supports multiple
}

他のヒント

you can use modernizr which is developed for this purpose.

http://modernizr.com/

you can detect support of a feature like placeholder in this way:

if (!Modernizr.input.placeholder) {

}

As taken & edited from the Modernizr source:

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

You don't need to include a complete library if this is the only thing you need.

I suggest you use Modernizr javascript library? This provides a way to check if browsers support various features.

You can use Modernizr, which does a huge number of these tests for you.

In this case, though, the test is really easy:

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

The same is true of all the other new properties on elements.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top