将鼠标指针移出图片时调用函数:
<img onmouseleave="normalImg(this)" src="smiley.gif" alt="Smiley">
亲自试一试 »
下面有更多示例。
这个onmouseleave
事件发生时鼠标指针离开元素。
这个onmouseleave
事件经常与onmouseenter
事件,当鼠标指针进入元素时发生。
这个onmouseleave
事件类似于onmouseout
事件。不同之处在于onmouseleave
事件不会冒泡(不会向上传播文档层次结构)。请参阅本页底部的 "More Examples" 以更好地了解差异。
Event | Occurs When |
---|---|
onclick | The user clicks on an element |
oncontextmenu | The user right-clicks on an element |
ondblclick | The user double-clicks on an element |
onmousedown | A mouse button is pressed over an element |
onmouseenter | The pointer is moved onto an element |
onmouseleave | The pointer is moved out of an element |
onmousemove | The pointer is moving over an element |
onmouseout | The mouse pointer moves out of an element |
onmouseover | The mouse pointer is moved over an element |
onmouseup | The mouse button is released over an element |
气泡: | 不 |
---|---|
可取消: | 不 |
事件类型: | 鼠标事件 |
HTML 标签: | 所有 HTML 元素,除了:<base>、<bdo>、<br>、<head>、<html>、<iframe>、<meta>、<param>、<script>、<style> 和 <title> |
DOM 版本: | 2 级活动 |
此示例演示了 onmousemove、onmouseleave 和 onmouseout 事件之间的区别:
<div onmousemove="myMoveFunction()">
<p id="demo1">I will demonstrate onmousemove!</p>
</div>
<div onmouseleave="myLeaveFunction()">
<p id="demo2">I will demonstrate onmouseleave!</p>
</div>
<div onmouseout="myOutFunction()">
<p id="demo3">I will demonstrate onmouseout!</p>
</div>
亲自试一试 »
onmouseleave
是 DOM Level 2 (2001) 功能。
所有浏览器都完全支持它:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | 9-11 |
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!