http://enanim.tistory.com/230

JQuery 마우스 오버 이미지(img src) 변경


<script>
$(document).ready(function(){
 $(".leftimg").mouseover(function (){
  var file = $(this).attr('src').split('/');
  var filename = file[file.length-1];
  var path = '';
  for(i=0 ; i < file.length-1 ; i++){
   path = ( i == 0 )?path + file[i]:path + '/' + file[i];
  }
  $(this).attr('src',path+'/'+filename.replace('.gif','_on.gif'));
  
 }).mouseout(function(){
  var file = $(this).attr('src').split('/');
  var filename = file[file.length-1];
  var path = '';
  for(i=0 ; i < file.length-1 ; i++){
   path = ( i == 0 )?path + file[i]:path + '/' + file[i];
  }
  $(this).attr('src',path+'/'+filename.replace('_on.gif','.gif'));
 });
});
</script>
<ul>
 <li><img src="images/Leftmenu/member/amenu_01_on.gif" width="170" height="30" border="0" class="leftimg" /></li>
 <li><img src="images/Leftmenu/member/amenu_02.gif" width="170" height="30" border="0" class="leftimg" /></li>
 <li><img src="images/Leftmenu/member/amenu_03.gif" width="170" height="30" border="0" class="leftimg" /></li>
</ul>
Posted by [czar]
,