Last active
March 10, 2019 03:26
-
-
Save beiweiqiang/114dcc063a68e8a97732e30e04181adc to your computer and use it in GitHub Desktop.
defer's script 的执行时机
This file contains hidden or 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> | |
<script src="index.js" defer></script> | |
</head> | |
<body> | |
<div> | |
123123 | |
</div> | |
<img id="img" src="https://via.placeholder.com/1500" alt="img"> | |
<script> | |
</script> | |
</body> | |
</html> |
This file contains hidden or 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
console.log('index.js: 1 -> -> ', 'index'); | |
debugger; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment