HTML onmouseover 事件
onmouseover 事件在鼠标指针移动到元素上时触发。
实例
当鼠标指针移动到图像上时执行一段 JavaScript:
<!DOCTYPE html><html><body><img onmouseover="bigImg(this)" onmouseout="normalImg(this)" border="0" src="/images/smiley.gif" alt="Smiley" width="32" height="32"><p>当用户将鼠标移到图像上时,会触发函数 bigImg。此功能可放大图像。</p><p>当鼠标指针移出图像时,会触发函数 normalImg。该函数将图像的高度和宽度设置回正常值。</p><script>function bigImg(x) {x.style.height = "64px";x.style.width = "64px";}function normalImg(x) {x.style.height = "32px";x.style.width = "32px";}</script></body></html>
浏览器支持
| 事件 | |||||
|---|---|---|---|---|---|
| onmouseover | Yes | Yes | Yes | Yes | Yes |
所有主流浏览器都支持 onmouseover 事件。
定义和用法
onmouseover 事件在鼠标指针移动到元素上时触发。
注释:onmouseover 事件不适用以下元素:<base>、<bdo>、<br>、<head>、<html>、<iframe>、<meta>、<param>、<script>、<style> 或 <title>。
HTML 4.01 与 HTML5 之间的差异
无。
语法
<element onmouseover="script">
属性值
| 值 | 描述 |
|---|---|
| script | onmouseover 发生时运行的脚本。 |