javascript - 鼠标离开不触发(嵌套)
问题描述
为什么鼠标离开不射击。
$('.tlcr').hide();
$('.tli')
.on({
mouseenter: function() {
$('.tlcr').hide();
const index = $(this).index('.tli');
$('.tlcr').eq(index).show();
},
mouseleave: function() {
$('.tlcr').eq(index)
.on({
mouseenter: function() {
$('.tlcr').eq(index).show();
}, mouseleave: function() {
$('.tlcr').hide();
}
});
$('.tlcr').hide();
}
});
上面的代码变成了小提琴:https ://jsfiddle.net/czqab09j/3/
我想实现这一点:https ://jsfiddle.net/aLquks1c/1/
但我想用第一把小提琴的代码来实现它。但我做错了什么。
解决方案
我让它工作了,这是更新的代码:
$('.tli')
.on({
mouseenter: function() {
$('.tlcr').hide();
const index = $(this).index('.tli');
$('.tlcr').eq(index).show();
},
mouseleave: function() {
$('.tlcr').eq(index)
.on({
mouseenter: function() {
$('.tlcr').eq(index).show();
}
});
}
});
$('.tlcr')
.on({
mouseleave: function() {
$('.tlcr').hide();
}
});
我基本上删除了嵌套的鼠标离开功能并使其独立。
在这里查看小提琴的结果:https ://jsfiddle.net/czqab09j/4/
推荐阅读
- javascript - 从 Web 应用程序中使用 Javascript 打开 URL
- python - 如何将 PCA 与 SOM 相结合,以便在 python 中获得适当的数据点集群?
- python - OAuth期间如何访问多个钱包?
- laravel - 使用关系列订购主模型
- php - 如何显示十进制数,以便整数部分显示较大的文本大小而小数部分显示较小
- angular - 当参数在角度 11 中为“整数”时,无法获取 json 中的数据
- git - git如何创建文件责备?
- javascript - TypeError:无法读取/设置 null 的属性“样式”
- javascript - Jquery 表单验证不起作用(错误的属性值?)
- html - 背景图像上的属性值无效且图像未显示