2013-07-08 9 views
0

mouseleave 함수에 current_src 값을 전달해야합니다.jQuery - 마우스 오버 기능 내에서 변수를 가져올 수 없습니다. (mouseleave)

console.log는 undefined을 반환합니다.

var current_src, swap_src; 
jQuery(".browseProductImage").hover(
    function(){ 
     current_src = jQuery(this).attr('src'); 
     var swap_src = jQuery(this).next().attr('src'); 
     jQuery(this).attr('src', swap_src); 
    }, 
    function(){ 
     jQuery(this).attr('src', current_src); 
     console.log(current_src) 
    } 
); 

답변

1

당신이 여기 상단 범위 지정 하나의 변수를 사용하려면, current_src에 대한 var 두 번째를 제거합니다. 감사!
+0

가 그냥 자리 :

var current_src, swap_src; jQuery(".browseProductImage").hover( function(){ var current_src = jQuery(this).attr('src'); var swap_src = jQuery(this).next().attr('src'); jQuery(this).attr('src', swap_src); }, function(){ jQuery(this).attr('src', current_src); console.log(current_src) } ); 
RhymeGuy

+0

어쨌든 답변을 수락하는 것을 고려하십시오 ... –