jQuery改变鼠标滚动图像 [英] jquery change image on mouse rollover
问题描述
我一直有这个问题。我认为这应该是非常简单的,但我似乎无法得到它的工作。我想在滚动我的Facebook按钮时出现一个新图片。感谢您的帮助!
< p align =right>
< a href =http://www.facebook.com/AerialistPress>< img height =30pxid =Facebookclass =changePadalt =Aerialist Press Facebook Page src =/ sites / aerialist.localhost / files / images / facebook300.jpg/>< / a>
< a href =http://twitter.com/#!/AerialistPress> < img height =30pxclass =changePadalt =Aerialist Press Twitter Pagesrc =/ sites / aerialist.localhost / files / images / twitter300.jpg/>< / a>
< a href =http://www.pinterest.com/aerialistpress>< img height =30pxclass =changePadalt =Aerialist按Pinterest页面src =/ sites /aerialist.localhost/files/images/pinterest300.jpg/>< / a>
< / p>
< script>
jQuery(document).ready(function(){
jQuery('#facebook')。mouseover(function(){jQuery('#facebook')。attr('src')。replace '/sites/aerialist.localhost/files/images/facebook-roll.jpg');})
});
< / script>
attr 方法返回指定属性的值(在本例中为'src'),并且 replace
试图修改该字符串并返回一个新实例。然而,你并没有对新实例做任何事情。
要设置属性,您必须将其他参数传递给 attr
方法。
以下是 attr
方法的文档:
http://api.jquery.com/attr/
你的代码应该是:
$ p $ jQuery('#facebook')。attr('src','/ sites / aerialist。本地主机/文件/图像/ Facebook的roll.jpg');
I have been having problems with this. I think this should be pretty simple but I cannot seem to get it to work. I want a new image to appear when rolling over my facebook button. Thanks for your help!
<p align="right">
<a href="http://www.facebook.com/AerialistPress" ><img height="30px" id="facebook" class="changePad" alt="Aerialist Press Facebook Page" src="/sites/aerialist.localhost/files/images/facebook300.jpg" /></a>
<a href="http://twitter.com/#!/AerialistPress" > <img height="30px" class="changePad" alt="Aerialist Press Twitter Page" src="/sites/aerialist.localhost/files/images/twitter300.jpg" /></a>
<a href="http://www.pinterest.com/aerialistpress" ><img height="30px" class="changePad" alt="Aerialist Press Pinterest Page" src="/sites/aerialist.localhost/files/images/pinterest300.jpg" /></a>
</p>
<script>
jQuery(document).ready(function(){
jQuery('#facebook').mouseover(function() { jQuery('#facebook').attr('src').replace('/sites/aerialist.localhost/files/images/facebook-roll.jpg'); })
});
</script>
The attr
method returns the value of the property specified (in this case, 'src'), and the replace
is trying to modify the string and return a new instance. However, you're not doing anything with the new instance.
To set the attribute you must pass an additional parameter to the attr
method.
Here's the documentation for the attr
method:
http://api.jquery.com/attr/
Your code should be:
jQuery('#facebook').attr('src', '/sites/aerialist.localhost/files/images/facebook-roll.jpg');
这篇关于jQuery改变鼠标滚动图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!