Set a time field to read-only:
document.getElementById("myTime").readOnly = true;
Click the button to set the time field to read-only.
<!DOCTYPE html> <html> <body> Time: <input type="time" id="myTime"> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {/*from www. j av a2 s .c o m*/ document.getElementById("myTime").readOnly = true; } </script> </body> </html>
The readOnly
property sets or gets whether a input field should be read-only, or not.
A read-only field cannot be modified.
This property mirrors the HTML readonly attribute.
The <input type="time"> element is not supported in Firefox.
The readOnly
property accepts and returns a String type value.
Value | Description |
---|---|
true | The time field is read-only |
false | Default. The time field is not read-only |
The readOnly
property returns true if the time field is read-only, otherwise it returns false.