简单教程
提交运行
代码编辑器:
<p>该范例使用了 addEventListener() 方法向 h1 元素添加 "mouseenter" 和 "mouseleave" 事件</p> <h1 id="demo">Mouse over me</h1> <script> document.getElementById("demo").addEventListener("mouseenter", mouseEnter); document.getElementById("demo").addEventListener("mouseleave", mouseLeave); function mouseEnter() { document.getElementById("demo").style.color = "red"; } function mouseLeave() { document.getElementById("demo").style.color = "black"; } </script>
运行结果: