开发者

onchange on date inputs [duplicate]

This question already has answers here: Closed 11 years ago.

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)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜