HTML onmouseover 事件

onmouseover 事件在鼠标指针移动到元素上时触发。


实例

当鼠标指针移动到图像上时执行一段 JavaScript:

  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4. <img onmouseover="bigImg(this)" onmouseout="normalImg(this)" border="0" src="/images/smiley.gif" alt="Smiley" width="32" height="32">
  5. <p>当用户将鼠标移到图像上时,会触发函数 bigImg。此功能可放大图像。</p>
  6. <p>当鼠标指针移出图像时,会触发函数 normalImg。该函数将图像的高度和宽度设置回正常值。</p>
  7. <script>
  8. function bigImg(x) {
  9. x.style.height = "64px";
  10. x.style.width = "64px";
  11. }
  12. function normalImg(x) {
  13. x.style.height = "32px";
  14. x.style.width = "32px";
  15. }
  16. </script>
  17. </body>
  18. </html>

浏览器支持

事件
onmouseoverYesYesYesYesYes

所有主流浏览器都支持 onmouseover 事件。


定义和用法

onmouseover 事件在鼠标指针移动到元素上时触发。

注释:onmouseover 事件不适用以下元素:<base>、<bdo>、<br>、<head>、<html>、<iframe>、<meta>、<param>、<script>、<style> 或 <title>。


HTML 4.01 与 HTML5 之间的差异

无。


语法

  1. <element onmouseover="script">
属性值
描述
scriptonmouseover 发生时运行的脚本。