当前位置:网站首页>Uncaught ReferenceError: Cannot access ‘f1‘ before initialization
Uncaught ReferenceError: Cannot access ‘f1‘ before initialization
2022-08-06 18:08:00 【今天不学习,明天变腊鸡】
Uncaught ReferenceError: Cannot access ‘f1’ before initialization
翻译:未捕获的引用错误:初始化前无法访问“f1”
可知是没有初始化,发生错误的原因很简单,就是在没有预先定义函数的基础上使用了函数。
<!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>事件的添加与删除</title>
</head>
<body>
<button>元素对象</button>
<button>元素事件监听器</button>
<button>事件派发器/广告联盟点击赚钱</button>
<!-- 目标1: 1.事件对象的使用(设置和取消) 2.设置监听器(设置和取消) 3.搞懂冒泡 -->
<script> let btn1 = document.querySelector('button:first-of-type'); //事件函数只能够用标准的函数 let f1 = () => {
console.log(123); } btn1.onclick = f1; </script>
</body>
</html>
如上面代码所示,必须先定义函数再使用
其中btn1.onclick = f1;btn1.onclick = f1();有本质区别btn1.onclick = f1;自定义了事件,及每一次点击按钮,就调用一次函数btn1.onclick = f1();就是调用一次函数
边栏推荐
猜你喜欢

ESP8266-Arduino编程实例-力敏电阻传感器

Sketch91: How to set an aligned reference object and align it according to the specified element tutorial

作业8.6 进程间的通信 消息队列与共享内存

Using the interface address pool for direct networking segment allocation

ESP8266-Arduino programming example-force sensitive resistance sensor

数据权限就该这么实现(实践篇),yyds!

OpenInfra Days China 2022|SelectDB shares with you the practice of Apache Doris in Internet advertising business

PreScan快速入门到精通第二十二讲驾驶员模型之路径跟踪

Is the code more messy?That's because you don't use Chain of Responsibility!

用u盘装系统教程操作图解
随机推荐
对标西湖大学,年薪60万博士后招聘来了
Nextcloud -6- 同步上传文件限制1M问题解决方案
数据化管理洞悉零售及电子商务运营——商品中的数据化管理
Remember to configure the expiration time of @Cacheable (Redis specifies the expiration time of certain Cache Keys)
PreScan快速入门到精通第二十二讲驾驶员模型之路径跟踪
用u盘装系统教程操作图解
Butterfly魔改:网址卡片外挂标签
论文阅读笔记(四)——实例分割与掩模R-CNN应用于多摄像机设置中松散的奶牛
Mathematical ` ` uniform continuity
JUC并发容器1(CopyOnWriteArrayList、CopyOnWriteArraySet、ConcurrentSkipListSet)
Redis basis
Redux知识点总结
Flyway error source code analysis - Validate failed: Migrations have failed validation
`English` 2022/8/4
ESP8266-Arduino Programming Example-Reed Switch Sensor Driver
8.paddlepaddle之loss损失函数自定义
方舟开服配置教程服务器怎么开
亚马逊测评系统是什么,跨境卖家如何通过自己养号来实现快速出单?
See three years of CRUD programmers how to solve the database deadlock
PreScan快速入门到精通第二十讲之执行器(交通参与者)