将鼠标悬停在同级元素上的 jquery 上轻拂
mouseover jquery on sibling elements flick
$('body').on({
mouseenter: function () {
$(this).siblings('span').show();
},
mouseleave: function () {
$(this).siblings('span').show().hide();
}
}, "div");
我像这样放置我的 html
<div></div>
<span>x</span>
当我将鼠标悬停在跨度上时它会闪烁,如何在不将跨度作为孩子移动到 DOM 中的框中的情况下解决这个问题?
这是因为您没有正确附加事件:
$('body div').hover(function(){//mouseover event
$(this).next().show();
},function(){//mouseleave event
$(this).next().hide();
});
您还可以缩小代码范围以在悬停时使用.toggle()
:
$('body').on('hover','div',function(){
$(this).next().toggle();
});
由于要将事件绑定到span:
$('body').on("hover", "span", function(){
$(this).show();
},function(){
$(this).hide();
});
您甚至可以使用mouseenter和mouseleave:
$('body').on("mouseenter","span", function(){
$(this).show();
}).on("mouseleave", "span",function(){
$(this).hide();
});
相关文章:
- Firefox赢得了'不会显示我添加的jquery元素,但Chrome会显示
- 使用返回函数sinde.attr()jquery元素
- Wooccommerce所有JS和Jquery元素都未加载
- 追加JQuery元素和Angular
- 如何获取jQuery集合中的第k个元素..作为JQUERY元素
- 是否存在jQuery元素选择库的最小化版本
- 不能同时通过类和数字 ID 选择 jquery 元素
- 为什么jquery元素在ipad上没有响应
- Jquery元素用法
- 用于获取jQuery元素或值的方法
- 淡入淡出切换jquery元素
- 用于查找在 jQuery 元素集中具有特定类的元素的索引的单行代码
- 选择具有由 data() 设置的某个值的 JQuery 元素
- Jquery 元素的高级过滤
- 链接到另一个带有jQuery元素的页面
- jQuery:通过 .wrap() 添加到 DOM 的 jQuery 元素上的切换类
- 将字符串转换为 jquery 元素并将其追加到 DOM 中
- 与“click”事件一起存储的jQuery元素未按要求工作
- 在哈希数组中保存对 jquery 元素的引用
- 如何从核心JavaScript选择中获取jquery元素