We're looking for a user researcher to understand the needs of developers and designers. Is this you or someone you know? Check out the post: https://mzl.la/2IGzdXS

Blob 物件的 type 屬性提供檔案的 MIME 類別。若無法辨明型別則回傳空字串。


var mimetype = instanceOfFile.type



var i, fileInput, files, allowedFileTypes;

// fileInput 是個 HTMLInputElement: <input type="file" multiple id="myfileinput">
fileInput = document.getElementById("myfileinput");

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

// 這範例接受 *.png, *.jpeg 和 *.gif 圖片。
allowedFileTypes = ["image/png", "image/jpeg", "image/gif"];

for (i = 0; i < files.length; i++) {
  // 測試 file.type 是否是允許的類別。
  if (allowedFileTypes.indexOf(files[i].type) > -1) {
    // 若符合則執行這裡的程式碼。


規格 狀態 備註
File API
The definition of 'type' in that specification.
Working Draft 初定義


We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains. Find out how you can help!

功能 Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
File.type 5 (Yes) 4.0 (2) 10.0 11.10 5.1
功能 Android Edge Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
File.type No support (Yes) No support No support No support No support



此頁面的貢獻者: flyinglimao
最近更新: flyinglimao,