区分 HTMLElement的两个表单事件 input 和 change 事件

Aphorism

Grow In Errors!

input事件

The DOM input event is fired synchronously when the value of an , , or element is changed. For input elements with type=checkbox or type=radio, the input event should fire when a user toggles the control (via touch, mouse or keyboard) per the HTML5 specification

Additionally, the input event fires on a contenteditable editor when its contents are changed. In this case, the event target is the editing host element. If there are two or more elements which have contenteditable as true, “editing host” is the nearest ancestor element whose parent isn’t editable. Similarly, it’s also fired on root element of designMode editors.

input 事件在 input ,select , textarea 元素的值 改变的时候 同步触发

vue 中的 v-model 就是利用了该事件

change 事件

The change event is used by the HTML DOM API in two scenarios:

It’s fired for , , and elements when a change to the element’s value is committed by the user. Unlike the input event, the change event is not necessarily fired for each change to an element’s value.

It’s fired at AudioTrackList, VideoTrackList, and TextTrackList objects when one or more of the object’s tracks are enabled or disabled.

change 事件在用户 提交 元素值的改变 的时候被触发,并不是元素值改变就触发,需要提交本次的改变

元素 失去焦点的时候 视为一次提交

supplement

本本框输入的时候可能会使用的到的其他事件

1、compositionstart:官方解释,触发于一段文字的输入之前,也就是在输入一段需要的文本(第一个字母开始)或语音开始输入时会触发。
2、compositionupdate访问data:正插入的新字符;
3、compositionend访问data:插入的所有字符;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值