ボタンタイププロパティ
例
ボタンのタイプを返します。
var x = document.getElementById("myBtn").type;
定義と使用法
typeプロパティは、ボタンのタイプを設定または返します。
ヒント:ボタンのtype属性は常に指定してください。Internet Explorerのデフォルトのタイプは「ボタン」ですが、他のブラウザー(およびW3C仕様)では「送信」です。
ブラウザのサポート
Property | |||||
---|---|---|---|---|---|
type | Yes | Yes | Yes | Yes | Yes |
構文
typeプロパティを返します。
buttonObject.type
typeプロパティを設定します。
buttonObject.type = "submit|button|reset"
プロパティ値
Value | Description |
---|---|
submit | The button is a submit button (this is default for all browsers, except Internet Explorer) |
button | The button is a clickable button (this is default for Internet Explorer) |
reset | The button is a reset button (clears form data) |
技術的な詳細
戻り値: | ボタンタイプを表す文字列 |
---|
その他の例
例
ボタンのタイプを「送信」に変更します。
document.getElementById("myBtn").type = "submit";
例
ボタンのタイプを「リセット」に変更します。
document.getElementById("myBtn").type = "reset";
関連ページ
HTMLリファレンス:HTML <button>タイプ属性
❮ボタンオブジェクト