当鼠标指针悬停在 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>

更新时间: 2020 年 5 月 30 日

284 次浏览

启动你的 职业生涯

通过完成该课程获得认证

开始
广告
© . All rights reserved.