JS四

输出

输出形式

1
2
3
4
alert() //弹出
console.log() //控制台
document.write() //文档输出
innerHtml //html输出

js获取DOM

id

1
document.getElementById() //唯一

class

1
document.getementByclass()

tag

1
2
3
4
5
6
```
## 变量作用域
### 全局变量
最外层声明的变量
在函数体内部,但是是没有声明var的变量也是全局变量

var a = 1;
function fn1(){
b =2;
console.log(a);
console.log(b);
}
console.log(a);
console.log(b);

1
2
3
### 局部变量
在函数体内部声明的变量

function fn2(){
var c = 3;
console.log(c)
}
console.log(c)

1
2
3
4
5
6
## 事件三要素
事件源 事件 事件处理程序
### window.onload 入口函数
等页面加载完毕之后 ,才开始执行函数体内的js部分
也就是说等页面的结构,样式,图片加载完毕


```