日期输入onchange [英] onchange on date inputs
本文介绍了日期输入onchange的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Possible Duplicate:
What events does an <input type=“number” /> fire when it's value is changed?
我有一个日期输入字段
<input type="date" name="..">
在webkit和firefox中,将在输入的侧面添加两个向上/向下箭头.单击它们时,日期会向前或向后移动,但是onchange事件不会触发,直到该字段失去焦点为止.有解决方法吗?
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?
推荐答案
您可以将值存储在全局变量中,并检查onclick的差异.
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;
}
};
或者,重复的问题,如评论建议. (请参见oninput
事件)
Or, duplicate question, like comments suggest. (See oninput
event)
这篇关于日期输入onchange的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文