In what authorative specification is the onChange event exhaustively defined?

不羁的心 提交于 2019-12-10 16:01:07

问题


I was slightly surprised to find out that the onChange event in an html document is fired on a text input or textarea not at the very moment when its value actually changes, but only when focus leaves the element (if its value has changed, of course).

So I was looking for the specification that states that, and I can't find it. I can find millions of tutorials explaining that, including W3Schools' ones, but I can't find the standard that defines when the event is expected to be fired.

In the HTML5 specification itself, the event's name is listed but nothing is said about it: http://www.w3.org/html/wg/drafts/html/master/

In this other spec, "DOM level 3 Events Specification", it is not even mentioned: http://www.w3.org/TR/DOM-Level-3-Events/

So what is the standard that defines it?


回答1:


It's briefly mentioned in the Intrinsic events section of the W3C 4.01 specification:

"The onchange event occurs when a control loses the input focus and its value has been modified since gaining focus".

It's also mentioned a little more extensively on MSDN:

"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 when the user commits the change by leaving the text box that has focus. In addition, this event is executed before the code specified by onblur when the control is also losing the focus."

Finally, on the MDN:

Depending on the kind of the form element being changed and the way the user interacts with the element, the change event fires at a different moment:

  • When the element is activated (by clicking or using the keyboard) for <input type="radio"> and <input type="checkbox">;
  • When the user commits the change explicitly (e.g. by selecting a value from a <select>'s dropdown with a mouse click, by selecting a date from a date pickier for <input type="date">, by selecting a file in the file picker for <input type="file">, etc.);
  • When the element loses focus after its value was changed, but not committed (e.g. after editing the value of <textarea> or <input type="text">).

Another potentially useful link - WhatWg - specification - change event.



来源:https://stackoverflow.com/questions/17329566/in-what-authorative-specification-is-the-onchange-event-exhaustively-defined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!