[英]javascript mouseover image swap issues
I am trying to swap out a hover image with javascript but it doesn't seem to be working, any idea why? 我正在尝试用javascript换出一个悬停图片,但是它似乎没有用,为什么? I thought this was the correct way to do this.
我认为这是正确的方法。
<li>
<a onMouseOver="document.fbi.src=images/facebookIconHover.jpg" onMouseOut="document.fbi.src=images/facebookIcon.jpg"
href="http://www.facebook.com">
<img src="images/facebookIcon.jpg" NAME="fbi">
</a>
</li>
It looks like all you need to do (assuming those images exists) is put single quotes around the src
string. 看起来您需要做的所有事情(假设这些图像存在)是在
src
字符串两边加上单引号。
onMouseOver="document.fbi.src='images/facebookIconHover.jpg'"
onMouseOut="document.fbi.src='images/facebookIcon.jpg'"
I would suggest you use CSS :hover
for the images though, as it separates presentation from content/scripting. 我建议您将CSS
:hover
用于图像,因为它将显示与内容/脚本分开。
#element {
background-image:url('url1.png');
}
#element:hover {
background-image:url('url2.png');
}
Via jQuery: 通过jQuery:
$('img[name="fbi"]').hover(function(){
$(this).attr('src','images/facebookIconHover.jpg');
},function(){
$(this).attr('src','images/facebookIcon.jpg');
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.