aboutsummaryrefslogtreecommitdiff
path: root/files/zh-tw/web/api/blob/size/index.html
blob: 2003a88cde748b831c045aec074a67fe167e09bd (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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
---
title: Blob.size
slug: Web/API/Blob/size
tags:
  - API
  - Files
  - Property
  - Reference
  - WebAPI
  - 參考
  - 屬性
translation_of: Web/API/Blob/size
---
<div>{{APIRef("File API")}}</div>

<p><strong><code>Blob.size</code></strong> 屬性回傳以 byte 為單位的 {{domxref("Blob")}} 或一個 {{domxref("File")}} 的大小。</p>

<h2 id="語法">語法</h2>

<pre class="syntaxbox">var sizeInBytes = <em>blob</em>.size
</pre>

<h2 id="值"></h2>

<p>一個數字。</p>

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

<pre class="brush:js">// fileInput 是個 HTMLInputElement: &lt;input type="file" multiple id="myfileinput"&gt;
var fileInput = document.getElementById("myfileinput");

// files 是個 FileList 物件 (類似 NodeList)
var files = fileInput.files;

for (var i = 0; i &lt; files.length; i++) {
  console.log(files[i].name + " has a size of " + files[i].size + " Bytes");
}</pre>

<h2 id="規格">規格</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">規格</th>
   <th scope="col">狀態</th>
   <th scope="col">附註</th>
  </tr>
  <tr>
   <td>{{SpecName('File API', '#dfn-size', 'size')}}</td>
   <td>{{Spec2('File API')}}</td>
   <td>初定義</td>
  </tr>
 </tbody>
</table>

<h2 id="瀏覽器相容性">瀏覽器相容性</h2>

{{Compat("api.Blob.size")}}

<h2 id="參見">參見</h2>

<ul>
 <li>{{domxref("Blob")}}</li>
</ul>