HTMLInputElement: accept 屬性

Baseline 已廣泛支援

此特性已相當成熟,可在許多裝置和瀏覽器版本上使用。自 ⁨2015 年 7 月⁩以來,各瀏覽器均已提供此特性。

accept 屬性是 HTMLInputElement 介面的一部分,它反映了 <input> 元素的 accept 屬性。該屬性通常是一個逗號分隔的檔案型別識別符號列表,用於提示 <input type="file"> 元素期望的檔案型別。如果未顯式設定該屬性,則 accept 屬性為空字串。

一個字串,表示元素的 accept 值,如果未顯式設定 accept,則為空字串。

示例

js
const inputElement = document.querySelector("#time");
console.log(inputElement.accept); // the current value of the accept attribute
inputElement.accept = ".doc,.docx,.xml,application/msword"; // sets the accept value

規範

規範
HTML
# dom-input-accept

瀏覽器相容性

另見