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事件和預想的不同。

相關文章
相關標籤/搜索