html change 事件

The change event is fired for <input><select>, and <textarea> elements when a change to the element's value is committed by the user. Unlike the inputevent, the change event is not necessarily fired for each change to an element's value.spa

事件在元素input,select,textarea的内容由用户改变的时候触发,而且不像input事件每一次的改变都触发。code

Description

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

  • 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 picker for <input type="date">, by selecting a file in the file picker for <input type="file">, etc.);ip

  • When the element loses focus after its value was changed, but not commited (e.g. after editing the value of <textarea> or <input type="text">).ci

Different browsers do not always agree whether a change event should be fired for certain types of interaction. For example, keyboard navigation in <select>elements never fires a change event in Gecko until the user hits Enter or switches the focus away from the <select> (see bug 126379).element

描述pdo

事件触发依赖于元素类型,触发方式以及触发不一样时刻,以下所示get

  • 对于<input type='radio'>和<input type="checkbox">,元素激活时触发(经过点击或者键盘)input

  • 用户明确提交更改(例如,鼠标点击选取select,从 <input type="date">选取日期,从<input type="file">选取文件)

  • 元素失去焦点时内容以改变,但并未提交(例如 <textarea> 或者 <input type="text">)也会触发、

不一样的游览器不保证特定类型的交互触发change事件。例如,在Gecko,除非用户点击enter或者从<select>移去焦点,经过键盘选取select将不会触发change事件。


引用:https://developer.mozilla.org/en-US/docs/Web/Events/change


**

怪不得不少change事件和预想的不同。

相关文章
相关标签/搜索