博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
如何在纯JavaScript中等待DOM ready事件
阅读量:2504 次
发布时间:2019-05-11

本文共 807 字,大约阅读时间需要 2 分钟。

You can do so by adding an event listener to the document object for the DOMContentLoaded event:

您可以通过将事件监听器添加到DOMContentLoaded事件的document对象中来实现:

document.addEventListener('DOMContentLoaded', (event) => {  //the event occurred})

I usually don’t use arrow functions inside for the event callback, because we cannot access this.

我通常不在事件回调中使用箭头函数,因为我们无法访问this

In this case we don’t need so, because this is always document. In any other event listener I would just use a regular function:

在这种情况下,我们不需要这样做,因为this始终是document 。 在任何其他事件侦听器中,我都将使用常规函数:

document.addEventListener('DOMContentLoaded', function(event) {  //the event occurred})

for example if I’m adding the event listener inside a loop and I don’t really know what this will be when the event is triggered.

例如,如果我加入一个循环内的事件监听器,我真的不知道this在触发事件会。

翻译自:

转载地址:http://moqgb.baihongyu.com/

你可能感兴趣的文章
开源SoC整理
查看>>
【2020-3-21】Mac安装Homebrew慢,解决办法
查看>>
influxdb 命令行输出时间为 yyyy-MM-dd HH:mm:ss(年月日时分秒)的方法
查看>>
已知子网掩码,确定ip地址范围
查看>>
判断时间或者数字是否连续
查看>>
docker-daemon.json各配置详解
查看>>
Docker(一)使用阿里云容器镜像服务
查看>>
Docker(三) 构建镜像
查看>>
FFmpeg 新旧版本编码 API 的区别
查看>>
RecyclerView 源码深入解析——绘制流程、缓存机制、动画等
查看>>
Android 面试题整理总结(一)Java 基础
查看>>
Android 面试题整理总结(二)Java 集合
查看>>
学习笔记_vnpy实战培训day02
查看>>
学习笔记_vnpy实战培训day03
查看>>
VNPY- VnTrader基本使用
查看>>
VNPY - CTA策略模块策略开发
查看>>
VNPY - 事件引擎
查看>>
MongoDB基本语法和操作入门
查看>>
学习笔记_vnpy实战培训day04_作业
查看>>
OCO订单(委托)
查看>>