フォームのenctypeプロパティ
例
サーバーに送信する前にフォームデータをエンコードする方法を返します。
var x = document.getElementById("myForm").enctype;
定義と使用法
enctypeプロパティは、フォームのenctype属性の値を設定または返します。
enctype属性は、フォームデータをサーバーに送信する前にエンコードする方法を指定します。
form-dataは、デフォルトで「application / x-www-form-urlencoded」にエンコードされます。これは、すべての文字がサーバーに送信される前にエンコードされることを意味します(スペースは「+」記号に変換され、特殊文字はASCII HEX値に変換されます)。
ブラウザのサポート
Property | |||||
---|---|---|---|---|---|
enctype | Yes | Yes | Yes | Yes | Yes |
構文
enctypeプロパティを返します。
formObject.enctype
enctypeプロパティを設定します。
formObject.enctype = "application/x-www-form-urlencoded,multipart/form-data,text/plain"
プロパティ値
Value | Description |
---|---|
application/x-www-form-urlencoded | All characters are encoded before sent (this is default) |
multipart/form-data | No characters are encoded. This value is required when you are using forms that have a file upload control |
text/plain | Spaces are converted to "+" symbols, but no special characters are encoded |
技術的な詳細
戻り値: | サーバーに送信する前にフォームデータをエンコードする方法を表す文字列 |
---|
その他の例
例
サーバーに送信する前にform-dataをエンコードする方法のenctype値を変更します。
document.getElementById("myForm").enctype = "multipart/form-data";
関連ページ
HTMLリファレンス:HTML <form> enctype属性
❮フォームオブジェクト