1.1-addEventListener注册事件
<!DOCTYPE html>
<html lang="zh-CN">
<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>Document</title>
</head>
<body>
<div class="box">我是小马哥</div>
<script>
const box = document.querySelector('.box')
box.onclick = function () {
box.style.backgroundColor = 'red'
}
box.onclick = function () {
box.style.height = 100 + 'px'
}
box.addEventListener('click', function () {
box.style.backgroundColor = 'red'
})
box.addEventListener('click', function () {
box.style.borderRadius = '50%'
})
box.addEventListener('click', myClick)
function myClick() {
box.style.textAlign = 'center'
}
</script>
</body>
</html>
1.2-removeEventListener移除事件
```html
<!DOCTYPE html>
<html lang="zh-CN">
<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>Document</title>
</head>
<body>
<div class="box">我是小马哥</div>
<script>
const box = document.querySelector('.box')
box.addEventListener('click', function () {
box.style.backgroundColor = 'red'
})
box.removeEventListener('click', function () {
box.style.backgroundColor = 'red'
})
box.addEventListener('click', myClick)
function myClick() {
box.style.height = 200 + 'px'
}
box.removeEventListener('click', myClick)
</script>
</body>
</html>