入力FileUploadacceptプロパティ
例
受け入れられるコンテンツタイプを変更します。
// The server will only accept audio files in the file upload
document.getElementById("myFile").accept = "audio/*";
定義と使用法
acceptプロパティは、ファイルアップロードボタンのaccept属性の値を設定または返します。
accept属性は、サーバーが受け入れるファイルのタイプを指定します(ファイルのアップロードを通じて送信できます)。
ブラウザのサポート
Property | |||||
---|---|---|---|---|---|
accept | Yes | Not supported | Yes | Not supported | Yes |
構文
acceptプロパティを返します。
fileuploadObject.accept
acceptプロパティを設定します。
fileuploadObject.accept = "audio/*,video/*,image/*,MIME_type"
プロパティ値
ヒント:複数の値を指定するには、値をコンマで区切ります。
Value | Description |
---|---|
audio/* | All sound files are accepted |
video/* | All video files are accepted |
image/* | All image files are accepted |
MIME_type | A valid MIME type, with no parameters. Look at IANA MIME types for a complete list of standard MIME types |
技術的な詳細
戻り値: | 受け入れられるコンテンツタイプのコンマ区切りリストを含む文字列 |
---|
その他の例
例
<input type = "file">要素の受け入れられたコンテンツタイプを表示します。
var x = document.getElementById("myFile").accept;
例
複数のコンテンツタイプを受け入れる:
// The server will only accept audio and video files in the file upload
document.getElementById("myFile").accept = "audio/*,video/*";
関連ページ
HTML参照:HTML <input>受け入れ属性
❮入力FileUploadオブジェクト