2016-07-14 35 views
0

所以這是我目前的腳本,但我似乎無法得到正確的鏈接,請幫助我,並添加一個鏈接(到一個子頁面),當我點擊活動時,我將鼠標懸停在它的圖像。我需要在最後的</a>之前插入新行嗎?如何將鏈接添加到已獲得翻轉腳本的圖像?

<a href="URL ADDRESS"> 
    <img 
     src="test.com/test1.png"; 
     onmouseover="this.src='test.com/test2.png'"; 
     onmouseout="this.src='test.com/test1'"; /> 
</a> 

我已經嘗試了幾種方法,但我真的是新的在這個,我不能弄明白。

+0

Julius

+0

你應該包括所有相關的代碼,你的問題的一部分:http://stackoverflow.com/help/mcve – ManoDestra

+1

請使用編輯按鈕添加更多的細節,而不是寫入評論。 –

回答

1

請試試這個,分號是不必要的,並且放錯了位置!

<a href="URL ADDRESS"> 
<img src="test.com/test1.png" 
    onmouseover="this.src='test.com/test2.png'" 
    onmouseout="this.src='test.com/test1'"/> 
</a> 
0

改爲使用它。您的分號只與腳本處理程序相關。您將它們放在屬於無效HTML的屬性之外。並且src後面的那個不正確。

<a href="URL ADDRESS"> 
    <img 
     src="test.com/test1.png" 
     onmouseover="this.src='test.com/test2.png';" 
     onmouseout="this.src='test.com/test1';" /> 
</a> 
0

試試這個。
Ps。
我用的JQuery

$(document).ready(function(){ 
 
    $('img').hover(function(){ 
 
     $(this).attr('src','test.com/test2.png'); 
 
     $(this).parent('a').attr('href','link when mouse enter the img'); 
 
    },function(){ 
 
     $(this).attr('src','test.com/test1'); 
 
     $(this).parent('a').attr('href','link when mouse leave the img'); 
 
    }); 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<a href="URL ADDRESS"> 
 
    <img 
 
     src="test.com/test1.png"; 
 
     onmouseover="this.src='test.com/test2.png'"; 
 
     onmouseout="this.src='test.com/test1'"; /> 
 
</a>