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

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

Thuộc tính disabled của HTML DOM Input Color thiết lập/trả về xem Input Color có được kích hoạt hay vô hiệu hóa.

Cú pháp

Cú pháp như sau:

  • Trả về giá trị boolean - true/false:
inputColorObject.disabled
  • Thiết lập disabled thành booleanValue:
inputColorObject.disabled = booleanValue

Các giá trị boolean

Ở đây, 「booleanValue」 có thể là các giá trị sau:

booleanValueChi tiết
trueĐịnh nghĩa rằng input color bị vô hiệu hóa.
falseĐịnh nghĩa rằng input color không bị vô hiệu hóa và đây cũng là giá trị mặc định.

Ví dụ

Dưới đây là ví dụ về thuộc tính Input Color disabled:

<!DOCTYPE html> <html> <head> <title>Input Color Disabled</title> </head> <body> <form> Bộ chọn màu: <input type="color" id="Color" disabled> </form> <button onclick="enableColorInput()">Kích hoạt Color Input</button> <div id="divDisplay"></div> <script>    var divDisplay = document.getElementById("divDisplay");    var inputColor = document.getElementById("Color");    divDisplay.textContent = 'Color Input bị vô hiệu hóa: '+inputColor.disabled;    function enableColorInput() {       inputColor.disabled = false;       divDisplay.textContent = 'Color Input bị vô hiệu hóa: '+inputColor.disabled;    } </script> </body> </html>

Kết quả

Đoạn mã trên sẽ cho kết quả như sau:

Trước khi nhấn nút 『Kích hoạt Color Input』:

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

Sau khi nhấn nút 『Kích hoạt Color Input』:

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