HTML DOM 輸入文字表單屬性


HTML DOM 輸入文字表單屬性用於返回包含輸入文字域的表單引用。如果輸入文字域不在表單中,它將返回 NULL。該屬性是隻讀的。

語法

以下是輸入文字表單屬性的語法。

textObject.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>

輸出

將產生以下輸出 −

單擊獲取表單按鈕後 −

更新於: 19 年 2 月 2021 日

95 次瀏覽

開啟你的 職業生涯

完成課程以獲得認證

開始學習
廣告
© . All rights reserved.