Help!? IE9: onChange event doesn't fire when v

2019-02-15 17:37发布

问题:

We have a custom numeric textbox in asp.net. In the oninput event, the input is checked on invalid characters, and the value of the textbox is set. The OnChange event is handled to do some things after the user leaves the textbox. This works in firefox, chrome and IE8.

In IE9, the onchange event is not firing anymore, after the text is set in a previous event. This is the problem in short:

<input type="text" onKeyDown="this.value=this.value;" onChange="alert('test');" />

In this example, the onChange event will not fire in IE9. It doesn't matter what kind of event you use, OnKeyDown, OnInput, OnPropertyChange or whatever. When you change the OnKeyDown to "", the OnChange will fire.

Any idea why this is not working anymore in IE9, and how to fix this? Thanks!

Update: i tested if the 'onChange' fires when i leave the textbox with the TAB key. The onchange does not fire in IE9 when you press tab, but it does fire when you leave the textbox by a mouseclick somewhere on your form.

So why does the onchange event fire when leaving the textbox with a mouseclick, but not by pressing the tab key ?

回答1:

There is a bug of IE9 about onchange event, therefore maybe you could add onpropertychange event on the input(bind both two events):

<input type="text" onKeyDown="this.value=this.value;" onChange="alert('test');" onpropertychange="alert('change');" />

This is just a workaround, hope this help.