HTML DOM form 屬性
定義和用法
form 屬性可返回對包含該按鈕的表單的引用。
如果包含該按鈕,則返回一個 form 對象,如果未包含該按鈕,則返回 null。
語法
buttonObject.form
實例
下面的例子可返回包含按鈕的表單的 id:
<html>
<body>
<form id="form1">
<input type="button" value="Click me!" id="button1" />
</form>
<p>The id of the form containing the button is:
<script type="text/javascript">
x=document.getElementById('button1');
document.write(x.form.id
);
</script></p>
</body>
</html>