-
Notifications
You must be signed in to change notification settings - Fork 8k
/
index.md
51 lines (33 loc) · 1.06 KB
/
index.md
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
45
46
47
48
49
50
51
---
title: FileList.length
slug: Web/API/FileList/length
l10n:
sourceCommit: a122e87245c624ba56197641b4d7b21b643a6021
---
{{APIRef("File API")}}
{{domxref("FileList")}} の読み取り専用プロパティ **`length`** は、`FileList` に含まれるファイルの数を返します。
## 値
リスト中のファイルの数を表す数。
## 例
### 選択されたファイルの数を出力する
この例では、`FileList` の中のアイテム数を知るために `length` を使います。
#### HTML
```html
<input type="file" multiple />
<div class="output"></div>
```
#### JavaScript
```js
const fileInput = document.querySelector("input[type=file]");
const output = document.querySelector(".output");
fileInput.addEventListener("change", () => {
const fileList = fileInput.files;
output.textContent = `あなたは ${fileList.length} 個のファイルを選択しました`;
});
```
#### 結果
{{EmbedLiveSample("選択されたファイルの数を出力する")}}
## 仕様書
{{Specifications}}
## ブラウザーの互換性
{{Compat}}