<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
// 1.load 等待页面加载完毕,再回去执行回调函数
// window.addEventListener('load',function(){
// const btn = document.querySelector('button')
// btn.addEventListener('click',function(){
// alert(11)
// })
// })
// //等待图片加载完毕,再去执行代码
// img.addEventListener('load',function(){
// })
//2.DOMContentLoaded 无需等待样式表、图像等完全加载,事件被触发,
// 速度更快
document.addEventListener('DOMContentLoaded',function(){
const btn = document.querySelector('button')
btn.addEventListener('click',function(){
alert(11)
})
})
</script>
</head>
<body>
<button>点击</button>
</body>
</html>
09-页面加载事件
最新推荐文章于 2024-06-23 12:45:17 发布