2011-04-12 26 views
1

可能重複:
What events does an <input type=「number」 /> fire when it's value is changed?平變化上日期輸入

我有個日期輸入字段

<input type="date" name=".."> 

WebKit中和Firefox,它將被添加兩個上/向下箭頭在輸入側。點擊它們時,日期向前或向後,但onchange事件不會觸發,直到該領域失去焦點。有沒有解決方法?

+0

重複的問題http://stackoverflow.com/search?q=oninput – mplungjan 2011-04-12 10:00:01

+0

jquery .change()可能會幫助你[http://api.jquery.com/change/](http:/ /api.jquery.com/change/) – Alex 2011-04-12 10:03:24

+0

謝謝你們,當我寫下標題時,沒有匹配。對不起:) – tbleckert 2011-04-12 10:05:16

回答

3

您可以將值存儲在全局中,並檢查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 →

編輯:或者,重複的問題,這樣的評論建議。 (見oninput事件)