如何使用jQuery在鼠标上方更改图片?[JSFiddle]
如何使用jQuery在鼠标上方更改图片?[JSFiddle],jquery,css,image,Jquery,Css,Image,我想在鼠标上切换图片,在鼠标离开时恢复。可以这样做吗?试试这个,它对我有用:- $("div#test > img").mouseover(function(){ $(this).attr('src', 'http://www.google.co.uk/images/logos/ps_logo2a_cp.png'); }); $("div#test > img").mouseout(function(){ $(this).attr('src', 'http://www
我想在鼠标上切换图片,在鼠标离开时恢复。可以这样做吗?试试这个,它对我有用:-
$("div#test > img").mouseover(function(){
$(this).attr('src', 'http://www.google.co.uk/images/logos/ps_logo2a_cp.png');
});
$("div#test > img").mouseout(function(){
$(this).attr('src', 'http://www.google.co.uk/intl/en_ALL/images/logos/images_logo_lg.gif');
});
下次试着换一张照片,我们中的一些人还在工作:)。(相同的代码,不同的事件)和现场预览:是的,悬停可能是一个更整洁的解决方案。
$('#img').hover(function () {
$(this).data('old-src', $(this).attr('src')).attr('src', 'http://example.com/new_image.jpg');
}, function () {
$(this).attr('src', $(this).data('old-src'));
});