“改变”之间的区别是什么和“输入”事件为INPUT元素 [英] What is the difference between "change" and "input" event for an INPUT element

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

问题描述

有人可以告诉我,更改输入事件之间的区别是什么?



我正在使用jQuery添加它们:

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

它也适用于输入而不是更改



可能在事件排序相对于焦点有一些区别?

解决方案

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆