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

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

Thuộc tính disabled của đối tượng Input URL trong HTML DOM thiết lập hoặc trả về trạng thái vô hiệu hóa ô nhập URL. Khi disabled, ô không tương tác được, không gửi giá trị khi submit, hiển thị mờ.

Cú pháp

Lấy giá trị boolean

inputURLObject.disabled

Thiết lập disabled

inputURLObject.disabled = booleanValue

Các giá trị boolean

booleanValueChi tiết
TrueÔ URL bị vô hiệu hóa.
FalseÔ URL hoạt động bình thường (mặc định).

Ví dụ minh họa

Form email nhân viên: ô email có sẵn giá trị, nhấn nút khóa ô (disabled=true) và hiển thị đã submit:

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

Kết quả

  • Ban đầu: ô email xyz@abc.com cho chỉnh sửa.
  • Nhấn Xác nhận Email: ô bị xám, không sửa được, hiển thị "Email: xyz@abc.com đã gửi."

Lưu ý: Ví dụ dùng type="email" nhưng đối tượng là Input URL — tính chất disabled giống hệt nhau cho tất cả kiểu input.