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