Jquery选择器:如何:更改链接悬停时图像标记的src属性

Job*_*ror 3 jquery jquery-selectors

我需要在链接悬停时更改图像的src属性

<div class="clear span-33 last" id="navigation">
  <div class="hicon span-1"><a href="#" title="Homepage"><img src="../Assets/images/home.png" /></a></div>
</div>   
Run Code Online (Sandbox Code Playgroud)

当链接没有悬停在...时也将其更改为默认值

Dav*_*ing 8

你真的应该考虑使用CSS sprites来悬停切换背景.但是如果你需要在jQuery中这样做,这样的事情就应该这样做.只需根据您的喜好更改过源图像(也可以预加载悬停图像):

var link = $('a'), 
    img  = link.children('img'), 
    orig = img.attr('src'), 
    over = 'over.png', 
    temp = new Image();

temp.src = over; // preloads

link.hover(function() {
    img.attr('src',over);
},function() {
    img.attr('src',orig);
}
Run Code Online (Sandbox Code Playgroud)