“onchange” event delayed in IE? (ok with Firefox)

前端 未结 6 1526
臣服心动
臣服心动 2020-12-10 07:56

It might be a beginner question but I can\'t understand why the onchange event is never called by IE while it works Ok with firefox.



        
6条回答
  •  余生分开走
    2020-12-10 08:33

    While annoying, it is not a bug that onchange is not fired until the element loses focus. (I get around the issue by having multiple bindings for different events; make sure not to clobber a handler and use an update aggregation if appropriate.)

    Here is the "official" W3C documentation on the subject:

    The onchange event occurs when a control loses the input focus and its value has been modified since gaining focus. This attribute applies to the following elements: INPUT, SELECT, and TEXTAREA.

    Here is the MSDN reference:

    This event is fired when the contents are committed and not while the value is changing. For example, on a text box, this event is not fired while the user is typing, but rather [it is fired] when the user commits the change by leaving the text box that has focus.

    The behavior, while often annoying, is as specified.

提交回复
热议问题