Input Button formプロパティ

Button 对象参考手册Button オブジェクト

定義と用法

form プロパティは、そのボタンを含むフォームへの参照を返します。

フォームにそのボタンが含まれている場合は form オブジェクトを返し、含まれていない場合は null を返します。

構文

buttonObject.form


ブラウザサポート

Internet ExplorerFirefoxOperaGoogle ChromeSafari

すべての主要ブラウザが form プロパティをサポートしています。


例

例

次の例では、ボタンを含むフォームの id を返します:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>サンプル(example.com)</title>
<script>
function displayResult(){
    var x=document.getElementById("button1").form.id;
    alert(x);
}
</script>
</head>
<body>

<form id="form1">
<input type="button" onclick="displayResult()" value="ボタンを含むフォームのIDを表示" id="button1">
</form>

</body>
</html>

試してみる »


Button 对象参考手册Button オブジェクト その他の拡張