运行 ❯
获取您
自己的
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <style> div { width: 150px; height: 100px; border: 1px solid black; margin: 10px; padding: 5px; text-align: center; background-color: lightgray; } </style> <body> <h1>HTML DOM Events</h1> <h2>The onmouseenter Event</h2> <p>This example demonstrates the difference between onmousemove, onmouseenter and onmouseover.</p> <div onmousemove="myMoveFunction()"> <p>onmousemove</p> <p id="demo1">Mouse over me!</p> </div> <div onmouseenter="myEnterFunction()"> <p>onmouseenter</p> <p id="demo2">Mouse over me!</p> </div> <div onmouseover="myOverFunction()"> <p>onmouseover</p> <p id="demo3">Mouse over me!</p> </div> <p>The onmousemove event occurs every time the mouse pointer is moved over an element.</p> <p>The mouseenter event only occurs when the mouse pointer enters an element. </p> <p>The onmouseover event occurs when the mouse pointer enters an div element.</p> <script> let x = 0; let y = 0; let z = 0; function myMoveFunction() { document.getElementById("demo1").innerHTML = z+=1; } function myEnterFunction() { document.getElementById("demo2").innerHTML = x+=1; } function myOverFunction() { document.getElementById("demo3").innerHTML = y+=1; } </script> </body> </html>