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

Thuộc tính readOnly của Input Date trong HTML DOM

Thuộc tính readOnly của HTML DOM Input Date thiết lập/trả về xem Input Date có thể được sửa đổi hay không.

Cú pháp

Cú pháp như sau:

  • Trả về giá trị boolean - true/false:
inputDateObject.readOnly
  • Thiết lập readOnly thành booleanValue:
inputDateObject.readOnly = 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 date là chỉ đọc (readOnly).
falseĐịnh nghĩa rằng input date không phải readOnly và có thể sửa đổi.

Ví dụ

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

<!DOCTYPE html> <html> <head> <title>Input Date readOnly</title> </head> <body> <form> Ngày thi cuối kỳ: <input type="date" id="dateSelect"> </form> <button onclick="finalizeDate()">Xác nhận ngày</button> <div id="divDisplay"></div> <script>    var divDisplay = document.getElementById("divDisplay");    var inputDate = document.getElementById("dateSelect");    divDisplay.textContent = 'Ngày thi đã xác nhận: '+inputDate.readOnly;    function finalizeDate() {       inputDate.readOnly = true;       divDisplay.textContent = 'Ngày thi: '+inputDate.value;    } </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 『Xác nhận ngày』:

Thuộc tính readOnly của Input Date trong HTML DOM

Sau khi nhấn nút 『Xác nhận ngày』:

Thuộc tính readOnly của Input Date trong HTML DOM