运行 ❯
获取您
自身
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <style> #myDIV { background-color: coral; padding: 16px; } </style> <body> <h1>The Element Object</h1> <h2>The removeEventListener() Method</h2> <div id="myDIV">This orange element has an onmousemove event handler that displays a random number when you move the mouse inside. <p>Click "Remove" to remove the event handler.</p> <button onclick="removeHandler()">Remove</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>