#
#
#
$(function(){ $("img.rollover").mouseover(function(){ $(this).attr("src",$(this).attr("src").replace(/^(.+)(\.[a-z]+)$/, "$1_on$2")); }).mouseout(function(){ $(this).attr("src",$(this).attr("src").replace(/^(.+)_on(\.[a-z]+)$/, "$1$2")); }).each(function(){ $("").attr("src",$(this).attr("src").replace(/^(.+)(\.[a-z]+)$/,"$1_on$2")); }); });
下のソースに書き換えて「jquery.rollover.js」に保存
$.fn.rollover = function(){ $(this).mouseover(function(){ $(this).attr("src",$(this).attr("src").replace(/^(.+)(\.[a-z]+)$/, "$1_on$2")); }).mouseout(function(){ $(this).attr("src",$(this).attr("src").replace(/^(.+)_on(\.[a-z]+)$/, "$1$2")); }).each(function(){ $("").attr("src",$(this).attr("src").replace(/^(.+)(\.[a-z]+)$/,"$1_on$2")); }); return this; }