html jQuery的でマウスオーバー画像を変更

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了html jQuery的でマウスオーバー画像を変更相关的知识,希望对你有一定的参考价值。

//通常時の画像には「_off」を、マウスオーバー時の画像には「_on」を付けて保存

/* javascript */
$(function(){
  $('a img').hover(function(){
    $(this).attr('src', $(this).attr('src').replace('_off', '_on'));
  }, function(){
    if (!$(this).hasClass('currentPage')) {
      $(this).attr('src', $(this).attr('src').replace('_on', '_off'));
    }
  });
});


/* html */
<a href="#">
  <img src="http://www.placehold.it/images/btn_sample_off.jpg" alt="btn_sample_off" />
</a>

以上是关于html jQuery的でマウスオーバー画像を変更的主要内容,如果未能解决你的问题,请参考以下文章