Button typeプロパティ
Button オブジェクト
定義と用法
type プロパティはボタンのタイプを設定または返します。
ヒント:常にボタンに type プロパティを指定してください。IE ブラウザのデフォルトタイプは "button" ですが、他のブラウザ(および W3C 仕様)では "submit" です。
構文
buttonObject.type=value
type プロパティは以下の値を取ることができます:
| 值 | 説明 |
|---|---|
| submit | button は送信ボタンです(IE 以外のすべてのブラウザのデフォルト値) |
| button | button はクリック可能なボタンです(IE のデフォルト値) |
| reset | button はリセットボタンです(フォームデータをクリア) |
ブラウザサポート
![]()
![]()
![]()
![]()
![]()
すべての主要ブラウザが type プロパティをサポートしています。
例
例
ボタンのタイプを返す:
<html>
<head>
<script>
function alertType()
{
alert(document.getElementById("myButton").type)
}
</script>
</head>
<body>
<button id="myButton" type="button" onclick="alertType()">Click Me!</button>
</body>
</html>
<head>
<script>
function alertType()
{
alert(document.getElementById("myButton").type)
}
</script>
</head>
<body>
<button id="myButton" type="button" onclick="alertType()">Click Me!</button>
</body>
</html>
試してみる »
Button オブジェクト その他の拡張