onmouseout 事件

定义和用法

onmouseout 事件会在鼠标指针移出指定的对象时发生。

语法

onmouseout="SomeJavaScriptCode"
参数 描述
SomeJavaScriptCode 必需。规定该事件发生时执行的 JavaScript。

支持该事件的 HTML 标签:

<a>, <address>, <area>, <b>, <bdo>, <big>, <blockquote>, <body>, <button>, 
<caption>, <cite>, <code>, <dd>, <dfn>, <div>, <dl>, <dt>, <em>, <fieldset>, 
<form>, <h1> to <h6>, <hr>, <i>, <img>, <input>, <kbd>, <label>, <legend>, 
<li>, <map>, <ol>, <p>, <pre>, <samp>, <select>, <small>, <span>, <strong>, 
<sub>, <sup>, <table>, <tbody>, <td>, <textarea>, <tfoot>, <th>, <thead>, 
<tr>, <tt>, <ul>, <var>

支持该事件的 JavaScript 对象:

layer, link

实例 1

在下面的例子中,我们将在鼠标指针移出图像时显示一个对话框:

<img src="/i/example_mouse2.jpg" alt="mouse"
onmousemove="alert('您的鼠标刚才离开了图片!')" />

输出:(请把鼠标从图片上移开):

Visit W3School!

实例 2

下面的例子中,我们将在网页上添加一个用作连接按钮的图像,然后我们会添加 onMouseOver 和 onMouseOut 事件,这样就可以在运行两个 JavaScript 函数来切换两幅图像:

<html>
<head>
<script type="text/javascript">
function mouseOver()
{
document.getElementById('b1').src ="/i/eg_mouse.jpg"
}
function mouseOut()
{
document.getElementById('b1').src ="/i/eg_mouse2.jpg"
}
</script>
</head>

<body>
<a href="http://www.w3school.com.cn" 
onmouseover="mouseOver()" onmouseout="mouseOut()">
<img alt="Visit W3School!" src="/i/example_mouse2.jpg" id="b1" />
</a>
</body>
</html>

输出:

Visit W3School!

TIY

onmouseout
如何使用 onmouseout。