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

HTML DOM Input Email Thuộc tính tự động lấy nét

Thuộc tính tự động lấy nét Email đầu vào HTML DOM đặt / trả về liệu Email đầu vào có được tập trung khi tải trang đầu tiên hay không.

Cú pháp

Sau đây là cú pháp -

  • Trả về giá trị boolean - true / false
inputEmailObject.autofocus
  • Đặt tự động lấy nét sang booleanValue
inputEmailObject.autofocus = booleanValue

Giá trị Boolean

Đây, “booleanValue” có thể như sau -

booleanValue Chi tiết
true Nó xác định rằng đầu vào sẽ được lấy nét tự động khi tải trang.
false Đây là giá trị mặc định và đầu vào không được lấy nét tự động.

Ví dụ

Hãy để chúng tôi xem ví dụ về Tự động lấy nét email nhập tài sản -

<!DOCTYPE html>
<html>
<head>
<title>Input Email autofocus</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>
<fieldset>
<legend>Email-autofocus</legend>
<label for="EmailSelect">User Email :
<input type="email" id="EmailSelect" placeholder="eg: xyz@abc.com" autofocus>
</label>
<input type="button" onclick="removeAutofocus()" value="Remove Autofocus">
<div id="divDisplay"></div>
</fieldset>
</form>
<script>
   var divDisplay = document.getElementById("divDisplay");
   var inputEmail = document.getElementById("EmailSelect");
   divDisplay.textContent = 'Autofocus: '+inputEmail.autofocus;
   function removeAutofocus() {
      inputEmail.autofocus = false;
      divDisplay.textContent = 'Autofocus: '+inputEmail.autofocus;
   }
</script>
</body>
</html>

Đầu ra

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

Trước khi nhấp vào 'Xóa tự động lấy nét' nút -

HTML DOM Input Email Thuộc tính tự động lấy nét

Sau khi nhấp vào ‘Xóa tự động lấy nét’ nút -

HTML DOM Input Email Thuộc tính tự động lấy nét