The autofocus
property sets or gets
whether a datetime field can automatically get focus when the page loads.
autofocus |
No | No | No | No | No |
Return the autofocus property.
var v = datetimeObject.autofocus
Set the autofocus property.
datetimeObject.autofocus=true|false
Value | Description |
---|---|
true|false | Set whether a datetime field should get focus when the page loads
|
A Boolean type value, true if the datetime field automatically gets focus when the page loads, otherwise false.
The following code shows how to get if a datetime field can automatically get focus upon page load.
<!DOCTYPE html>
<html>
<body>
<input type="datetime" id="myDatetime" autofocus>
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {<!--from w w w.j ava 2 s .c o m-->
var x = document.getElementById("myDatetime").autofocus;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
The code above is rendered as follows: