1.点语法注册事件:事件源.事件类型=事件处理函数
<body>
<div id="box" style="width: 100px;height: 100px;background-color: red"></div>
<script>
let box = document.querySelector('#box')
box.onclick = function() {
console.log(111);
}
</script>
</body>
2.addEventListener()注册事件
<div id="box" style="width: 100px;height: 100px;background-color: red"></div>
<script>
let box = document.querySelector('#box')
box.addEventListener('click', function() {
alert('天天向上')
})
</script>
下节讲区别与移除事件