onmouseover 時間會在鼠標指針移動到指定的對象上時發(fā)生。
onmouseover="SomeJavaScriptCode"
參數(shù) | 描述 |
---|---|
SomeJavaScriptCode | 必需。規(guī)定該事件發(fā)生時執(zhí)行的 JavaScript。 |
<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>
layer, link
在下面的例子中,我們將在用戶把鼠標指針移動到圖像上時顯示一個對話框:
<img src="/i/eg_mouse2.jpg" alt="mouse"onmouseover="alert('您的鼠標在圖片上!')"
/>
下面的例子中,我們將在網頁上添加一個用作連接按鈕的圖像,然后我們會添加 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 onmouseout="mouseOut()"><img alt="Visit W3School!" src="/i/eg_mouse2.jpg" id="b1" /></a></body></html>