doc: create window load event section
This commit is contained in:
1 parent
b67bd27003
commit
a1c4270f4b
1 file changed
+15
-1
@@ -69,4 +69,18 @@ for (let i = 0; i < divs.length; i++) {
|
||||
}) ();
|
||||
```
|
||||
- 将文件的所有代码包装在一个声明并立即调用的匿名函数中,详情[请看](http://adripofjavascript.com/blog/drips/an-introduction-to-iffes-immediately-invoked-function-expressions.html)
|
||||
- 不会有全局符号被引入!
|
||||
- 不会有全局符号被引入!
|
||||
|
||||
### 监听窗口“load”事件
|
||||
您只能在“load”事件触发后访问document元素。
|
||||
```javascript
|
||||
"use strict";
|
||||
(function() {
|
||||
window.addEventListener("load", init);
|
||||
// 这里没有权限查看文件
|
||||
function init() {
|
||||
// 我们现在可以访问DOM树了!
|
||||
// 在这里设置初始文档事件处理程序。
|
||||
}
|
||||
})();
|
||||
```
|
||||
Reference in new issue
Block a user