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