onmouseover 事件 | HTML DOM 事件对象

返回到:DOM 对象:HTML DOM 事件对象

定义和用法

onmouseover 事件会在鼠标指针移动到指定的元素上时发生。

语法

HTML 中:

<element onmouseover="SomeJavaScriptCode">

JavaScript 中:

object.onmouseover=function(){SomeJavaScriptCode};
参数描述
SomeJavaScriptCode必需。规定该事件发生时执行的 JavaScript。

The onmouseover event 所有主要浏览器都支持

支持该事件的 HTML 标签:

onmouseover 属性可使用于所有 HTML 元素,除了: <base>, <bdo>, <br>, <head>, <html>, <iframe>, <meta>, <param>, <script>, <style>, 和 <title>。

实例

鼠标指针移动到图片后执行Javascript代码:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Web176教程(Web176.com)</title>
<script>
function bigImg(x){
	x.style.height="64px";
	x.style.width="64px";
}
function normalImg(x){
	x.style.height="32px";
	x.style.width="32px";
}
</script>
</head>
<body>

<img onmouseover="bigImg(this)" onmouseout="normalImg(this)" border="0" src="/images/logo.svg" alt="Smiley" width="32" height="32">
<p>函数 bigImg() 在鼠标指针移动到笑脸图片是触发。</p>
<p>函数 normalImg() 在鼠标指针移出笑脸图片是触发.</p>

</body>
</html>

作者:terry,如若转载,请注明出处:https://www.web176.com/javascriptbook/domtips/3877.html

(0)
打赏 支付宝 支付宝 微信 微信
terryterry
上一篇 2021年9月24日 下午3:34
下一篇 2021年9月24日 下午3:41

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注