The Input Time object represents an HTML <input> element with type="time".
We can access an <input> element with type="time" by using getElementById().
<!DOCTYPE html>
<html>
<body>
<input type="time" id="myTime" value="22:15:00">
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {<!-- w w w .j a v a 2 s .c om-->
var x = document.getElementById("myTime").value;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
The code above is rendered as follows:
We can create an <input> element with type="time" by using the document.createElement() method.
<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">test</button>
<script>
function myFunction() {<!-- www. j a va 2s .com-->
var x = document.createElement("INPUT");
x.setAttribute("type", "time");
x.setAttribute("value", "22:35:09");
document.body.appendChild(x);
}
</script>
</body>
</html>
The code above is rendered as follows:
Property | Description |
---|---|
autocomplete | Sets or gets the autocomplete attribute of a time field |
autofocus | Sets or gets whether a time field can auto focus when the page loads |
defaultValue | Sets or gets the default value of a time field |
disabled | Disable or enable a time field |
form | Get the form that contains the time field |
list | Get the datalist that contains the time field |
max | Sets or gets the max attribute of the time field |
min | Sets or gets the min attribute of the time field |
name | Sets or gets the name attribute of a time field |
readOnly | Sets or gets whether the time field is read-only |
required | Sets or gets whether the time field must be filled before submitting a form |
step | Sets or gets the step attribute of the time field |
type | Get the type of the time field |
value | Sets or gets the value attribute of a time field |
Method | Description |
---|---|
blur() | Removes focus from a time field |
focus() | Gives focus to a time field |
The Input Time object supports the standard properties and events.