运行 ❯
获取您的
自有
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 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 onmouseleave Event</h2> <p>This example demonstrates the difference between onmousemove, onmouseleave and onmouseout.</p> <div onmousemove="myMoveFunction()"> <p>onmousemove</p> <p id="demo1">Mouse over and leave me!</p> </div> <div onmouseleave="myLeaveFunction()"> <p>onmouseleave</p> <p id="demo2">Mouse over and leave me!</p> </div> <div onmouseout="myOutFunction()"> <p>onmouseout</p> <p id="demo3">Mouse over and leave me!</p> </div> <p>The onmousemove event occurs every time the mouse pointer is moved over an div element.</p> <p>The mouseleave event only occurs when the mouse pointer is moved out of an element. </p> <p>The onmouseout event occurs when the mouse pointer is moved out of an element.</p> <script> let x = 0; let y = 0; let z = 0; function myMoveFunction() { document.getElementById("demo1").innerHTML = z+=1; } function myLeaveFunction() { document.getElementById("demo2").innerHTML = x+=1; } function myOutFunction() { document.getElementById("demo3").innerHTML = y+=1; } </script> </body> </html>