2017-10-05 115 views
0

我試圖調整部位的側面圖像,每個按鈕應該像更改爲不同的SRC,我嘗試這樣做:變化IMG SRC

$(document).ready(function(){ 

    $("#introID").hover(function(){ 
     $("#frame").attr("src", "newImage.png"); 
    }); 
}); 

等少數變化,但由於某種原因,jQuery不捕捉?或者也許這是我的語法?從我inderstanding我只是

這裏是我的html:

<html> 
<head> 
<meta charset="utf-8"> 
<title>CAPP</title> 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"> 
    $(document).ready(function(){ 

    $("#introID").hover(function(){ 
     $("#frame").attr("src", "assets/images/much-more-than-gasoline.png"); 
    }); 
}); 


</script> 
<body> 

<div id="logodiv"> 
<img id="logo" src="logo.png" alt="logo"/> 
</div> 

<div id="h1s"> 
<img src = "Origionalimage.png" id="frame"/> 

    <div class="h1padding"></div> 
    <a class = "h1" href="" id="introID">Intro</a> 

    <div class="h1padding"></div> 
    <a class = "h1" href="">ON THE <span class="light">SURFACE</span></a> 

    <div class="h1padding"></div> 
    <a class = "h1" href="">From <span class="light">ore to oil</span></a> 

    <div class="h1padding"></div> 
    <a class = "h1" href="">Environmental <span class="light">care</span></a> 

    <div class="h1padding"></div> 
    <a class = "h1" href="">Much more than <span class="light">gasoline</span></a> 

    <div class="h1padding"></div> 
    <a class = "h1" href="">One more <span class="light">thing</span></a> 

</div> 




</body> 

感謝提前:)

回答

0

如果src屬性設置不得嵌入script標籤內您自己的腳本。

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> 
<script> 
    $(document).ready(function(){ 
     $("#introID").hover(function(){ 
      $("#frame").attr("src", "assets/images/much-more-than-gasoline.png"); 
     }); 
    }); 
</script> 

這應該做的伎倆。 Here你會發現更多的信息。

+0

謝謝,這工作! – Rolthar