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

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

Thuộc tính disabled của đối tượng Input Email xác định xem trường email có bị vô hiệu hóa hay không.

Cú pháp

Lấy giá trị (true/false)

inputEmailObject.disabled

Thiết lập giá trị

inputEmailObject.disabled = booleanValue

Giá trị Boolean

Giá trịMô tả
trueTrường email bị vô hiệu hóa (mờ, không nhập, không gửi giá trị).
falseMặc định: trường email hoạt động bình thường.

Ví dụ minh họa

Vô hiệu hóa trường email sau khi xác nhận:

<!DOCTYPE html>
<html>
<head>
<title>Input Email disabled</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-disabled</legend>
    <label for="EmailSelect">Email nhân viên: <input type="email" id="EmailSelect" value="xyz@abc.com"> </label>
    <input type="button" onclick="getdisabled()" value="Xác nhận Email">
    <div id="divDisplay"></div>
  </fieldset>
</form>
<script>
  var divDisplay = document.getElementById("divDisplay");
  var inputEmail = document.getElementById("EmailSelect");
  function getdisabled() {
    inputEmail.disabled = true;
    divDisplay.textContent = 'Email: ' + inputEmail.value + ' đã gửi.';
  }
</script>
</body>
</html>

Kết quả

Ban đầu trường email có thể chỉnh sửa. Sau khi nhấn nút, trường bị disable (disabled = true) và hiển thị thông báo đã gửi.