onmouseover 事件
定義和用法
onmouseover 事件會在鼠標指針移動到指定的對象上時發(fā)生。
語法
onmouseover="SomeJavaScriptCode"
參數(shù) | 描述 |
---|---|
SomeJavaScriptCode | 必需。規(guī)定該事件發(fā)生時執(zhí)行的 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/eg_mouse2.jpg" alt="mouse"
onmouseover="alert('您的鼠標在圖片上!')"
/>
輸出:(請把鼠標移動圖片上):

實例 2
下面的例子中,我們將在網(wǎng)頁上添加一個用作連接按鈕的圖像,然后我們會添加 onMouseOver 和 onMouseOut 事件,這樣就可以在運行兩個 JavaScript 函數(shù)來切換兩幅圖像:
<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.dbjr.com.cn"
onmouseover="mouseOver()" onmouseout="mouseOut()"
>
<img alt="Visit W3School!" src="/i/eg_mouse2.jpg" id="b1" />
</a>
</body>
</html>
輸出:

TIY
- onmouseover
- 如何使用 onmouseover。