小码哥的IT人生

HTML DOM form 属性

JavaScript基础 2022-06-08 16:00:03小码哥的IT人生shichen

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>

TIY

完整实例【返回包含按钮的表单的 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>

可以使用本站在线JavaScript测试工具测试上述代码运行效果:http://www.phpcodeweb.com/runjs.html

版权所有 © 小码哥的IT人生
Copyright © phpcodeweb All Rights Reserved
ICP备案号:苏ICP备17019232号-2  

苏公网安备 32030202000762号

© 2021-2024