HTML DOM Input Text form 属性

htmlweb developmentfront end technology更新于 2024/5/28 5:32:17

HTML DOM Input Text form 属性用于返回包含输入文本字段的表单引用。如果输入文本字段位于表单之外,则返回 NULL。此属性为只读属性。

语法

以下是输入文本表单属性的语法。

textObject.form

示例

让我们来看一个 Input Text form 属性的示例 −

<!DOCTYPE html>
<html>
<body>
<h1>Input Text form Property</h1>
<form id="NEW_FORM">
USERNAME: <input type="text" id="TEXT1">
</form>
<p>Get the form id by clicking on the below button</p>
<button type="button" onclick="formId()">GET FORM</button>
<p id="Sample"></p>
<script>
   function formId() {
      var P=document.getElementById("TEXT1").form.id;
      document.getElementById("Sample").innerHTML = "The id of the form containing the text field is: "+P ;
   }
</script>
</body>
</html>

输出

这将产生以下输出 −

点击"获取表单"按钮 −


相关文章


有用资源