1. 面向开发者的 Web 技术
  2. Web API
  3. HTMLInputElement
  4. HTMLInputElement.multiple

此页面由社区从英文翻译而来。了解更多并加入 MDN Web Docs 社区。

View in English Always switch to English

HTMLInputElement.multiple

基线 广泛可用

自 2015年7月 起,此特性已在主流浏览器中得到支持,可在大多数设备和浏览器版本中正常使用。

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

实例

js
// fileInput is a <input type=file multiple>
let fileInput = document.getElementById("myfileinput");
if (fileInput.multiple == true) {
 for (let i = 0; i < fileInput.files.length; i++) {
 // Loop fileInput.files
 }
 // Only one file available
} else {
 let file = fileInput.files.item(0);
}

See also

Specification

Browser compatibility

帮助改进 MDN

了解如何参与贡献

此页面最后更新于 ,由 MDN 贡献者更新。

AltStyle によって変換されたページ (->オリジナル) /