Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/397.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jQuery-document.on悬停切换方法-错误_Javascript_Html_Jquery - Fatal编程技术网

Javascript jQuery-document.on悬停切换方法-错误

Javascript jQuery-document.on悬停切换方法-错误,javascript,html,jquery,Javascript,Html,Jquery,因此,我一直在尝试在jQuery中创建一个函数,当您将鼠标悬停在某个元素上时,它将切换img,当您退出该元素时,img将再次切换。唯一的问题是,这一切都发生在$(文档).onslector上。我尝试过使用$(document).off().on,但不起作用。这是我的密码: $(document).on('mouseover','.addressLink',function()){ var redirectSelector=$(this.children().last(); 重定向选择器。切换(

因此,我一直在尝试在jQuery中创建一个函数,当您将鼠标悬停在某个元素上时,它将切换img,当您退出该元素时,img将再次切换。唯一的问题是,这一切都发生在
$(文档).on
slector上。我尝试过使用
$(document).off().on
,但不起作用。这是我的密码:

$(document).on('mouseover','.addressLink',function()){
var redirectSelector=$(this.children().last();
重定向选择器。切换('fast');
$(这个)鼠标(
函数(){
重定向选择器。切换('fast');
});
});

单击以查找位置
$(document).on('mouseenter mouseleave','.addressLink',function(){
var redirectSelector=$(this.children().last();
重定向选择器。切换('fast');
});

单击以查找位置

我为你树立了榜样

$(document).on('mouseover mouseleave','.addressLink',函数(e){
var$img=$(this.find('img');
如果(e.type==='mouseover'){
$img.stop(true,true).slideDown('fast');
}否则{
$img.stop(true,true).slideUp('fast');
}
});
.addressLink img{
显示:块;
}

单击以查找位置

试试这个:

$('.addressLink')。悬停(函数(){
var redirectSelector=$(this.children().last();
重定向选择器。show('fast');
},函数(){
var redirectSelector=$(this.children().last();
重定向选择器。隐藏('fast');
}      
);

单击以查找位置

该问题最有可能与嵌套mouseleave绑定有关。每次将鼠标移到元素上时,都将创建一个新的mouseleave绑定,并且在第一次之后会有重复的绑定。由于您正在执行切换,而不仅仅是显式地执行添加或删除方法,所以您看到的是重复效果行为。简单的解决方案是,对mouseleave也使用委托事件处理程序。这不适用于动态创建的元素。