Home  >  Article  >  Web Front-end  >  input标签内容改变的触发事件介绍_javascript技巧

input标签内容改变的触发事件介绍_javascript技巧

WBOY
WBOYOriginal
2016-05-16 16:43:551497browse

1. onchange事件与onpropertychange事件的区别:

onchange事件在内容改变(两次内容有可能相等)且失去焦点时触发;onpropertychange事件是实时触发,每增加或删除一个字符就会触发,通过js改变也会触发该事件,但是该事件是IE专有。

2. oninput事件与onpropertychange事件的区别:

oninput事件是IE之外的大多数浏览器支持的事件,在value改变时实时触发,但是通过js改变value时不会触发;onpropertychange事件是任何属性改变都会触发,而oninput却只在value改变时触发,oninput要通过addEventListener()来注册,onpropertychange注册方法与一般事件相同。

3. oninput与onpropertychange失效的情况:

oninput事件:

(1)当脚本中改变value时,不会触发;

(2)从浏览器的自动下拉提示中选取时,不会触发;

onpropertychange事件:

当input设置为disable=true后,不会触发。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn