-
-
Save FlandreDaisuki/87da8921dc785a9e003aa1c0bb2dd7cc to your computer and use it in GitHub Desktop.
Dom相关事件的执行顺序
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name New Userscript | |
// @namespace https://github.com/ipcjs | |
// @version 0.0.1 | |
// @description try to take over the world! | |
// @author ipcjs | |
// @match http://bangumi.bilibili.com/anime/5788/play* | |
// @grant none | |
// @run-at document-start | |
// ==/UserScript== | |
(function () { | |
'use strict'; | |
window.addEventListener('load', (...args) => { | |
console.log(7, document.readyState, args, document.getElementById('index_nav')); | |
}); | |
window.addEventListener('DOMContentLoaded', (...args) => { | |
console.log(5, document.readyState, args, document.getElementById('index_nav')); | |
}); | |
document.addEventListener('readystatechange', (...args) => { | |
console.log(1, document.readyState, args, document.getElementById('index_nav')); | |
}); | |
document.addEventListener('DOMContentLoaded', (...args) => { | |
console.log(3, document.readyState, args, document.getElementById('index_nav')); | |
}); | |
document.addEventListener('DOMContentLoaded', (...args) => { | |
console.log(4, document.readyState, args, document.getElementById('index_nav')); | |
}); | |
window.addEventListener('DOMContentLoaded', (...args) => { | |
console.log(6, document.readyState, args, document.getElementById('index_nav')); | |
}); | |
document.addEventListener('readystatechange', (...args) => { | |
console.log(2, document.readyState, args, document.getElementById('index_nav')); | |
}); | |
window.addEventListener('load', (...args) => { | |
console.log(8, document.readyState, args, document.getElementById('index_nav')); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
結論
其中 2 和 3 的關係是因為事件 bubble,根據 whatwg:
DOMContentLoaded 和 這頁