2011-07-11 49 views
0

我有3個子彈圖像。 1表示激活,1表示懸停,1表示其餘鏈接。如何使用javascript實現懸停效果?

這是我的代碼。

<a href="#" class="toc selected" rel="2"><img src="images/othersdefdot.png" onclick="funcCaller('fund', 'images/reddot.png', 'local', 'images/othersdefdot.png', 'youthgames', 'images/othersdefdot.png')" name="fund"></a> 

如何在此鏈接中實現懸停效果?

Check the demo page here

感謝

回答

1
<a href="#" class="toc selected" onMouseover="showPic1()" onMouseout="showPic2()"> 
    <img id="link_img" src="/images/othersdefdot.png" /> 
</a> 

的Javascript:

function showPic1() { 
    document.getElementById('link_img').src = "/images/img1.png"; 
} 

function showPic2() { 
    document.getElementById('link_img').src = "/images/img2.png"; 
} 
+0

謝謝。我會試試這個 – Giri

0

我不完全知道你是問什麼,而是你可以使用onmouseover屬性。

<a href="#" class="toc selected" rel="2"><img src="images/othersdefdot.png" onclick="funcCaller('fund', 'images/reddot.png', 'local', 'images/othersdefdot.png', 'youthgames', 'images/othersdefdot.png')" onmouseover="javascriptFunction()" name="fund"></a> 
0

如果只是爲了懸停效果,沒有必要使用JavaScript。你可以只使用CSS:

a img:hover{ 
    /*change background*/ 
} 

但是如果你堅持,你可以事件處理onmousedown重視它。希望有所幫助。

+0

無法工作,因爲圖像會出現在背景之上。 – Nightfirecat