aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/htmlinputelement/multiple/index.html
blob: 937c52a93f4580683faa67e4f80e4cba33101656 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
---
title: HTMLInputElement.multiple
slug: Web/API/HTMLInputElement/multiple
translation_of: Web/API/HTMLInputElement/multiple
---
<div>{{ APIRef("HTML DOM") }}</div>

<p><strong><code>HTMLInputElement.multiple</code></strong> 属性表示一个input是否可以有多个值。目前只有火狐支持 <code>&lt;input type="file"&gt;</code>存有多个值。</p>

<h2 id="实例">实例</h2>

<pre class="brush:js">// fileInput is a &lt;input type=file multiple&gt;
let fileInput = document.getElementById('myfileinput');

if (fileInput.multiple == true) {

  for (let i = 0; i &lt; fileInput.files.length; i++) {
    // Loop fileInput.files
  }

// Only one file available
} else {
  let file = fileInput.files.item(0);
}
</pre>

<h2 id="See_also">See also</h2>

<ul>
 <li><a href="/en/DOM/FileList" title="en/DOM/FileList">FileList</a></li>
 <li><a class="link-https" href="https://bugzilla.mozilla.org/show_bug.cgi?id=523771" title="https://bugzilla.mozilla.org/show_bug.cgi?id=523771">Bug 523771</a> - <span class="bz_default_hidden" id="summary_alias_container" style="display: inline;"> <span id="short_desc_nonedit_display">Support &lt;input type=file multiple&gt;</span> </span></li>
</ul>

<h2 id="Specification">Specification</h2>

<ul>
 <li><a class="external" href="http://www.whatwg.org/specs/web-apps/current-work/multipage/common-input-element-attributes.html#attr-input-multiple" title="http://www.whatwg.org/specs/web-apps/current-work/multipage/common-input-element-attributes.html#attr-input-multiple">The multiple attribute</a> (HTML 5 working draft)</li>
</ul>

<h2 id="Browser_compatibility">Browser compatibility</h2>



<p>{{Compat("api.HTMLInputElement.multiple")}}</p>