The Input Datetime object represents an HTML <input> element with type="datetime".
Property | Description |
---|---|
autocomplete | Sets or gets the autocomplete attribute of a datetime field |
autofocus | Sets or gets whether a datetime field can automatically get focus when the page loads |
defaultValue | Sets or gets the default value of a datetime field |
disabled | Sets or gets whether a datetime field is disabled, or not |
form | Returns a reference to the form that contains the datetime field |
list | Get the datalist that contains the datetime field |
max | Sets or gets the max attribute of the datetime field |
min | Sets or gets the min attribute of the datetime field |
name | Sets or gets the name attribute of a datetime field |
readOnly | Sets or gets whether the datetime field is read-only |
required | Sets or gets whether the datetime field must be filled before submitting a form |
step | Sets or gets the step attribute of the datetime field |
type | Get the type of the datetime field |
value | Sets or gets the value attribute of a datetime field |
The Input Datetime object supports the standard properties and events.
We can access an <input> element with type="datetime" by using getElementById().
<!DOCTYPE html>
<html>
<body>
<input type="datetime" id="myDatetime" value="2014-03-02T10:57Z">
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<!--from w ww .jav a2s . com-->
<script>
function myFunction() {
var x = document.getElementById("myDatetime").value;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
The code above is rendered as follows:
We can create an <input> element with type="datetime" by using the document.createElement() method.
<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">test</button>
<script>
function myFunction() {<!-- w w w . ja va2 s . c om-->
var x = document.createElement("INPUT");
x.setAttribute("type", "datetime");
x.setAttribute("value", "2014-01-01T08:32Z");
document.body.appendChild(x);
}
</script>
</body>
</html>
The code above is rendered as follows: