它就是整个html网页文档,这点我们在浏览器控制台输入它即可展开查看
延迟执行(js代码可以写在html节点前面)
例如这段代码
<!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>test</title>
</head>
<body>
<script>
// 得到盒子1
var box1 = document.getElementById('box1');
// 得到盒子2
var box2 = document.getElementById('box2');
console.log(box1);
console.log(box2);
</script>
<div id="box1">我是盒子1</div>
<div id="box2">我是盒子2</div>
</body>
</html>
这样只能找前面的,所以找不到为null,因此一般我们将script标签放在最后或者相关联html结构的后面
不过当然也有将script标签对书写在前面的办法,不仅如此还能放在head标签对中
事件对象
<!DOCTYPE html>
<html lang="en">
<!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>test</title>
<script>
// 给windows对象添加onlad监听。onlad表示页面都加载完毕了
window.onlad= function() {
// 得到盒子1
var box1 = document.getElementById('box1');
// 得到盒子2
var box2 = document.getElementById('box2');
console.log(box1);
console.log(box2);
};
</script>
</head>
<body>
<div id="box1">我是盒子1</div>
<div id="box2">我是盒子2</div>
</body>
</html>
至于这个事件,后续进行讲解,我们现在只需知道怎么用就行了