在 HTML 中鼠标指针移过元素时如何执行脚本?


在 HTML 中,当鼠标指针移过元素时,onmouseover 属性被触发。

示例

你可以尝试运行以下代码来实现 onmouseover 属性 −

<!DOCTYPE html>
<html>
   <body>
      <h3 id = "myid" onmouseover = "display()">
         This is demo heading.
      </h3>
      <p>Keep the mouse cursor on the heading to change the color.</p>
      <script>
         function display() {
            document.getElementById("myid").style.color = "red";
         }
      </script>
   </body>
</html>

更新于: 30-5-2020

284 浏览量

开启你的 职业

通过完成课程获取认证

开始
广告
© . All rights reserved.