代码示例:(标识:jsck_element_addeventlistener_remove)
<!DOCTYPE html>
<html>

<style>
#myDIV {
  background-color: coral;
  padding: 16px;
}
</style>

<body>
<h1>Element 对象</h1>

<h2>addEventListener() 方法</h2>

<div id="myDIV">这个橙色元素有一个 onmousemove 事件处理程序,当您在其中移动鼠标时会显示随机数。
  <p>单击“删除”以删除事件处理程序。</p>
  <button onclick="removeHandler()">删除</button>
</div>

<p id="demo"></p>

<script>
const myDiv = document.getElementById("myDIV");
myDiv.addEventListener("mousemove", myFunction);

function removeHandler() {
  myDiv.removeEventListener("mousemove", myFunction);
}

function myFunction() {
  document.getElementById("demo").innerHTML = Math.random();
}
</script>

</body>
</html>
运行结果: