Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOM级别事件模型 #82

Open
XJIANBIN opened this issue Jan 18, 2023 · 0 comments
Open

DOM级别事件模型 #82

XJIANBIN opened this issue Jan 18, 2023 · 0 comments
Labels

Comments

@XJIANBIN
Copy link
Owner

DOM级别一共可以分为四个级别:DOM0级、DOM1级、DOM2级和DOM3级。而DOM事件分为3个级别:DOM0级事件处理,DOM2级事件处理和DOM3级事件处理。
为什么没有DOM1级事件处理呢?因为1级DOM标准并没有定义事件相关的内容,所以没有所谓的1级DOM事件模型。

DOM0 级

DOM0级处理事件就是将一个函数赋值给一个事件处理属性。
···js
var btn = document.getElementById('btn');
btn.onclick = function() {
console.log('Hello World');
}
``

DOM2级事件

DOM2级事件定义了addEventListener 和 removeEventListener两个方法

var btn = document.getElementById('btn');    
    function showFn() {
        alert('Hello World');
    }    
 btn.addEventListener('click', showFn, false);

DOM3级事件

DOM3级事件是在DOM2级事件的基础上添加很多事件类型。
UI事件,当用户与页面上的元素交互时触发,如:load、scroll
焦点事件,当元素获得或失去焦点时触发,如:blur、focus
鼠标事件,当用户通过鼠标在页面执行操作时触发如:dbclick、mouseup
滚轮事件,当使用鼠标滚轮或类似设备时触发,如:mousewheel
文本事件,当在文档中输入文本时触发,如:textInput
键盘事件,当用户通过键盘在页面上执行操作时触发,如:keydown、keypress
合成事件,当为IME(输入法编辑器)输入字符时触发,如:compositionstart
变动事件,当底层DOM结构发生变化时触发,如:DOMsubtreeModified

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant