HTMLInputElement: thuộc tính readOnly
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
Thuộc tính readOnly của giao diện HTMLInputElement cho biết người dùng không thể sửa đổi giá trị của <input>. Nó phản ánh thuộc tính boolean readonly của phần tử <input>; trả về true nếu thuộc tính hiện diện và false khi bị bỏ qua.
Không giống như điều khiển biểu mẫu có thuộc tính disabled là true, giá trị thuộc tính readOnly là true không ngăn người dùng nhấp hoặc chọn trong điều khiển.
Mặc dù thuộc tính HTML readonly bị bỏ qua nếu loại là hidden, range, color, checkbox, radio, file, submit, reset, button, và image, thuộc tính readOnly là true cho các loại đầu vào này nếu thuộc tính hiện diện, false nếu ngược lại.
Giá trị
Một boolean.
Ví dụ
const inputElement = document.getElementById("total");
console.log(inputElement.readOnly);
inputElement.readOnly = true;
Đặc tả kỹ thuật
| Specification |
|---|
| HTML> # dom-input-readonly> |