<div id="compv-navbar">
<a href="#"><img src="image1.png" id="icon1"></a> |
<a href="#"><img src="image2.png" id="icon2"></a> |
<a href="#"><img src="image3.png" id="icon3"></a> |
<span id="view_name"> 2-up</span>
</div>
假设新图像的名称遵循以下公式:
名称+“-悬停”。所以 image1.png = image1-hover.png"
最佳答案
您可以使用 .hover()
来做到这一点然后做一个.replace()
在 src
属性上,像这样:
$("#compv-navbar a img").hover(function() {
this.src = this.src.replace('.png', '-hover.png');
}, function() {
this.src = this.src.replace('-hover.png', '.png');
});
关于jquery - 如何使用 jQuery 在悬停时交换这些图标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3376646/