描述 (Description)
The onmouseover attribute is one of the most commonly used event attributes. It captures the moment that a cursor crosses the boundary of an element, moving from outside to inside the element to which the attribute is applied. It differs from the onmousemove attribute, which is used to detect movement within the element’s boundaries. Once the cursor is positioned over the element, the onmouseover event remains active until the cursor is moved beyond the element’s boundaries—an event that the onmouseout attribute would capture.
onmouseover属性是最常用的事件属性之一。 它捕获了光标越过元素边界的时刻,该时刻从应用属性的元素从外部移到内部。 它不同于onmousemove属性,后者用于检测元素边界内的移动。 一旦将光标定位在元素上,onmouseover事件将保持活动状态,直到将光标移到元素的边界之外— onmouseout属性将捕获该事件。
The onmouseover attribute is mostly used to render visual effects such as image swapping or color changes, and has been used in this way for almost as long as JavaScript has been around.
onmouseover属性主要用于呈现视觉效果,例如图像交换或颜色变化,并且几乎一直存在JavaScript时就一直以这种方式使用。
Note that this event attribute cannot be applied to the following elements:
请注意,此事件属性不能应用于以下元素:
- applet 小程序
- base 基础
- basefont 基本字体
- bdo do
- br br
- font 字形
- frame 帧
- frameset 框架集
- head 头
- html html
- iframe iframe
- isindex 索引
- meta 元
- param 参数
- script 脚本
- style 样式
- title 标题
例 (Example)
The example below shows a simple image swap technique, whereby mousing over the image causes the image to change to one that reveals a location on a map:
下面的示例显示了一种简单的图像交换技术,通过将鼠标悬停在图像上,图像会变为显示地图上某个位置的图像:
<div>
<img src="map.gif" alt="Hover to reveal the location on the map"
onmouseover="this.src='map_location_revealed.gif';"
onmouseout="this.src='map.gif';"/>Figures for February’s racing.
</div>
值 (Value)
This attribute has no fixed value. It’s up to the author to decide on the scripting that’s included here, be that a call to one or more defined functions, or a simple alert() statement.
此属性没有固定值。 由作者决定此处包含的脚本,是对一个或多个定义的函数的调用,还是简单的alert()语句。
兼容性 (Compatibility)
Internet Explorer | Firefox | Safari | Opera | |||||||
---|---|---|---|---|---|---|---|---|---|---|
5.5 | 6.0 | 7.0 | 1.0 | 1.5 | 2.0 | 1.3 | 2.0 | 3.0 | 9.2 | 9.5 |
Full | Full | Full | Full | Full | Full | Full | Full | Full | Full | Full |
IE浏览器 | 火狐浏览器 | 苹果浏览器 | 歌剧 | |||||||
---|---|---|---|---|---|---|---|---|---|---|
5.5 | 6.0 | 7.0 | 1.0 | 1.5 | 2.0 | 1.3 | 2.0 | 3.0 | 9.2 | 9.5 |
充分 | 充分 | 充分 | 充分 | 充分 | 充分 | 充分 | 充分 | 充分 | 充分 | 充分 |
Every browser listed supports this attribute. However, inline event handlers such as this should be avoided. In the same way that inline CSS styles are frowned upon but externally defined CSS styles are considered good practice, inline event handlers should be stripped out and replaced with events attached unobtrusively through the DOM.
列出的每个浏览器都支持此属性。 但是,应避免使用此类内联事件处理程序。 与不赞成使用内联CSS样式,但将外部定义CSS样式视为一种好习惯一样,应删除内联事件处理程序,并用通过DOM附加地添加事件来代替。