“改变”之间的区别是什么和“输入”事件为INPUT元素 [英] What is the difference between "change" and "input" event for an INPUT element
问题描述
更改
和输入
事件之间的区别是什么? 我正在使用jQuery添加它们:
$('input [type =text ]')on('change',function(){
pre>
alert($(this).val());
})
它也适用于
输入
而不是更改
可能在事件排序相对于焦点有一些区别?
解决方案p>根据这篇文章:
-
oninput
事件发生在通过用户界面更改元素的文本内容时。 -
onchange
发生在元素的选择,检查状态或内容已更改。在某些情况下,仅当元素失去焦点时才会发生。 onchange属性可以用于: < input>
,< select>
和< textarea>
。
我创建了演示这些东西的演示。
Can someone tell me what the difference between the change
and input
events is?
I am using jQuery for adding them:
$('input[type="text"]').on('change', function() {
alert($(this).val());
})
It also works with input
instead of change
.
Maybe some difference in the event ordering relative to focus?
According to this post:
oninput
event occurs when the text content of an element is changed through the user interface.onchange
occurs when the selection, the checked state or the contents of an element have changed. In some cases, it only occurs when the element loses the focus. The onchange attribute can be used with:<input>
,<select>
, and<textarea>
.
I've created a demo that demonstrates these things.
这篇关于“改变”之间的区别是什么和“输入”事件为INPUT元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!