Created
March 10, 2019 03:27
-
-
Save beiweiqiang/247cfea1ff773f45256a7cbcea61349a to your computer and use it in GitHub Desktop.
document 上的 DOMContentLoaded 事件 / window 上的 load 事件
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Title</title> | |
<script> | |
document.addEventListener('DOMContentLoaded', function (event) { | |
console.log('index.html: 9 -> -> ', 'dom'); | |
console.log('index.html: 10 -> -> ', document.getElementById('img').offsetWidth); | |
}); | |
window.addEventListener('load', function (event) { | |
console.log('index.html: 13 -> -> ', 'load'); | |
console.log('index.html: 15 -> -> ', document.getElementById('img').offsetWidth); | |
}); | |
</script> | |
</head> | |
<body> | |
<div> | |
123123 | |
</div> | |
<img id="img" src="https://via.placeholder.com/1500" alt="img"> | |
<script> | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment