程序时顺序执行的,script要写在网页框架后面。。。如果要书写在前面就要使用延迟执行就要将js语句块书写在
```js
window.onload = function(){
};
```
其中
<!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>
// 给window对象添加onload事件监听、、onload表示页面都加载完毕了
window.onload = 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>