gpt4 book ai didi

html - onChange 事件在哪个权威规范中有详尽的定义?

转载 作者:搜寻专家 更新时间:2023-10-31 08:33:30 25 4
gpt4 key购买 nike

我有点惊讶地发现 html 文档中的 onChange 事件是在文本输入或文本区域上触发的,而不是在其值实际发生变化的那一刻,而是仅在焦点离开元素时(如果其值发生变化) ,当然)。

所以我一直在寻找说明该内容的规范,但找不到。我可以找到数以百万计的教程来解释这一点,包括 W3School 的教程,但我找不到定义事件预计何时触发的标准。

在 HTML5 规范本身中,列出了事件的名称,但没有提及: http://www.w3.org/html/wg/drafts/html/master/

在另一个规范“DOM 级别 3 事件规范”中,甚至没有提到: http://www.w3.org/TR/DOM-Level-3-Events/

那么定义它的标准是什么?

最佳答案

它在 W3C 4.01 specification内部事件部分 中有简要提及。 :

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

它在 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."

最后,关于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">).

另一个可能有用的链接 - WhatWg - specification - change event.

关于html - onChange 事件在哪个权威规范中有详尽的定义?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17329566/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com