我想在鼠标上切换图片,并在鼠标离开时恢复。可以这样做吗?
答案 0 :(得分:2)
$('#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'));
});
答案 1 :(得分:1)
试试这个,它对我有用: -
$("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');
});