Uncaught ReferenceError: Cannot access ‘f1‘ before initialization

时间:2025-01-19 08:53:59
<!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>