onchange on date inputs [duplicate]
P开发者_StackOverflowossible Duplicate:
What events does an <input type=“number” /> fire when it's value is changed?
I have a date input field
<input type="date" name="..">
In webkit and firefox, it will be added two up/down arrows on the side of the input. When clicking them, the date goes forward or backwards, but the onchange event doesn't trigger until the field loses focus. Is there a workaround for this?
You could store the value in a global and check for a difference onclick.
<input type="date" name="myDate" id="myDate" />
var myApp = {};
myApp.myDate = "";
document.getElementById('myDate').onclick = function (e) {
if (this.value != myApp.myDate) {
// run onchange code
// then set last value to current value
myApp.myDate = this.value;
}
};
See example →
EDIT: Or, duplicate question, like comments suggest. (See oninput
event)
精彩评论