onmouseover(HTML元素)

描述 (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 ExplorerFirefoxSafariOpera
5.56.07.01.01.52.01.32.03.09.29.5
FullFullFullFullFullFullFullFullFullFullFull
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附加地添加事件来代替。

翻译自: https://www.sitepoint.com/onmouseover-html-element/

  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值