Computer >> Máy Tính >  >> Lập trình >> HTML

HTML DOM Input Gửi thuộc tính biểu mẫu

Thuộc tính biểu mẫu Gửi đầu vào HTML DOM được sử dụng để trả về tham chiếu biểu mẫu có chứa nút gửi nhất định. Nếu nút gửi nằm ngoài biểu mẫu thì nó sẽ chỉ trả về NULL. Thuộc tính này ở chế độ chỉ đọc.

Cú pháp

Sau đây là cú pháp cho thuộc tính biểu mẫu gửi đầu vào -

submitObject.form

Ví dụ

Chúng ta hãy xem một ví dụ cho thuộc tính biểu mẫu Gửi đầu vào -

<!DOCTYPE html>
<html>
<body>
<h1>Input submit form Property</h1>
<form action="Sample_page.php" id="FORM_1" style="border:solid 2px green;padding:2px">
UserName: <input type="text" id="USR"> <br>
Location: <input type="text" id=“Loc”> <br><br>
<input type="submit" id="SUBMIT1">
</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("SUBMIT1").form.id;
      document.getElementById("Sample").innerHTML = "The id of the form containing the submit
      button is: "+P ;
   }
</script>
</body>
</html>

Đầu ra

Điều này sẽ tạo ra kết quả sau -

HTML DOM Input Gửi thuộc tính biểu mẫu

Khi nhấp vào BIỂU MẪU -

HTML DOM Input Gửi thuộc tính biểu mẫu