HTMLInputElement: thuộc tính multiple

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

Thuộc tính HTMLInputElement.multiple cho biết liệu một đầu vào có thể có nhiều hơn một giá trị hay không. Firefox hiện chỉ hỗ trợ multiple cho <input type="file">.

Giá trị

Một giá trị boolean.

Ví dụ

html
<input id="my-file-input" type="file" multiple />
js
let fileInput = document.getElementById("my-file-input");

if (fileInput.multiple) {
  // Lặp qua fileInput.files
  for (const file of fileInput.files) {
    // Thực hiện hành động trên một tệp
  }
  // Chỉ có một tệp khả dụng
} else {
  let [file] = fileInput.files;
}

Đặc tả kỹ thuật

Specification
HTML
# dom-input-multiple

Tương thích trình duyệt

Xem thêm