The readOnly
property sets or gets whether
a input field should be read-only.
readOnly |
Yes | No | No | Yes | Yes |
Return the readOnly property.
var v = timeObject.readOnly
Set the readOnly property.
timeObject.readOnly=true|false
Value | Description |
---|---|
true|false | Set whether a time field should be read-only
|
A Boolean type value, true if the time field is read-only, otherwise false.
The following code shows how to get if a time field is read-only.
<!DOCTYPE html>
<html>
<body>
<!-- w w w . j ava 2 s. c om-->
Time: <input type="time" id="myTime" readonly>
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {
var x = document.getElementById("myTime").readOnly;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
The code above is rendered as follows:
The following code shows how to set a time field to read-only.
<!DOCTYPE html>
<html>
<body>
Time: <input type="time" id="myTime">
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<!-- w w w .j av a 2 s . c o m-->
<script>
function myFunction() {
document.getElementById("myTime").readOnly = true;
}
</script>
</body>
</html>
The code above is rendered as follows: