Change the image source on rollover using jQuery

前端 未结 14 1017
隐瞒了意图╮
隐瞒了意图╮ 2020-11-22 10:23

I have a few images and their rollover images. Using jQuery, I want to show/hide the rollover image when the onmousemove/onmouseout event happen. All my image names follow t

14条回答
  •  孤街浪徒
    2020-11-22 10:43

    $('img').mouseover(function(){
      var newSrc = $(this).attr("src").replace("image.gif", "imageover.gif");
      $(this).attr("src", newSrc); 
    });
    $('img').mouseout(function(){
      var newSrc = $(this).attr("src").replace("imageover.gif", "image.gif");
      $(this).attr("src", newSrc); 
    });
    

提交回复
热议问题