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