“改变"与“改变"的区别和“输入"`input` 元素的事件 [英] Difference between "change" and "input" event for an `input` element

查看:23
本文介绍了“改变"与“改变"的区别和“输入"`input` 元素的事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能告诉我 changeinput 事件之间的区别是什么?

Can someone tell me what the difference between the change and input events is?

我正在使用 jQuery 添加它们:

I am using jQuery for adding them:

$('input[type="text"]').on('change', function() {
    alert($(this).val());
})

它也适用于 input 而不是 change.

It also works with input instead of change.

与焦点相关的事件顺序可能有所不同?

Maybe some difference in the event ordering relative to focus?

推荐答案

根据 这篇文章:

  • oninput 事件在通过用户界面更改元素的文本内容时发生.

  • oninput event occurs when the text content of an element is changed through the user interface.

onchange 当元素的选择、选中状态或内容发生变化时发生.在某些情况下,它仅在元素失去焦点或按下 return (Enter) 并且值已更改时发生.onchange 属性可用于: