W3School TIY Editor
W3School 在线教程
改变方向
暗黑模式
运行代码
<!DOCTYPE html> <html> <body> <p>本例演示如何将 "onmouseenter" 和 "onmouseleave" 事件分配给 h1 元素。</p> <h1 id="demo" onmouseenter="mouseEnter()" onmouseleave="mouseLeave()">请把鼠标悬停在我上面</h1> <script> function mouseEnter() { document.getElementById("demo").style.color = "red"; } function mouseLeave() { document.getElementById("demo").style.color = "black"; } </script> </body> </html>