Javascript jQuery-无法在悬停函数(mouseleave)中获取变量

Javascript jQuery-无法在悬停函数(mouseleave)中获取变量,javascript,jquery,jquery-hover,mouseleave,mousehover,Javascript,Jquery,Jquery Hover,Mouseleave,Mousehover,我需要将current\u src的值传递给mouseleave函数 console.log返回未定义的 var current_src, swap_src; jQuery(".browseProductImage").hover( function(){ var current_src = jQuery(this).attr('src'); var swap_src = jQuery(this).next().attr('src'); j

我需要将
current\u src
的值传递给mouseleave函数

console.log返回未定义的

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)
    }
);

删除当前(src)的第二个
变量
,您希望在此处使用范围上限的一个变量:

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)
    }
);