Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> HTML

Thuộc tính form của HTML DOM Input Email

Thuộc tính form của đối tượng Input Email (<input type="email">) trả về tham chiếu đến phần tử <form> chứa trường email đó.

Cú pháp

Lấy tham chiếu form

inputEmailObject.form

Ví dụ minh họa

Xác nhận đăng nhập bằng cách hiển thị ID form chứa email:

<!DOCTYPE html>
<html>
<head>
<title>Input Email form</title>
<style>
  form { width:70%; margin: 0 auto; text-align: center; }
  * { padding: 2px; margin:5px; }
  input[type="button"] { border-radius: 10px; }
</style>
</head>
<body>
<form id="Multitech-MNC">
  <fieldset>
    <legend>Email-form</legend>
    <label for="EmailSelect">Email nhân viên: <input type="email" id="EmailSelect" value="xyz@abc.com"> </label>
    <input type="button" onclick="getform()" value="Xác nhận Email">
    <div id="divDisplay"></div>
  </fieldset>
</form>
<script>
  var divDisplay = document.getElementById("divDisplay");
  var inputEmail = document.getElementById("EmailSelect");
  function getform() {
    if(inputEmail.value !== '')
      divDisplay.textContent = 'Đang đăng nhập vào: ' + inputEmail.form.id;
    else
      divDisplay.textContent = 'Vui lòng nhập email hợp lệ';
  }
</script>
</body>
</html>

Kết quả

Nhấn "Xác nhận Email" để hiển thị ID form ("Multitech-MNC") nếu email đã nhập.