gpt4 book ai didi

jquery - 嵌套元素悬停 handle

转载 作者:行者123 更新时间:2023-12-01 01:01:51 24 4
gpt4 key购买 nike

所有,我遇到了处理嵌套元素悬停处理程序的问题。看来当鼠标进入 child div 时,祖先也处于 hover 状态,有没有办法触发祖先的 hoverout 事件,当鼠标进入 child 元素时?

下面是我到目前为止所做的努力。请查看。

<style>
div
{
border:1px solid red;
margin:10px;
padding:10px;
}
</style>


<script>
$(function() {
$('div').each(function(){
var current = this;
$(this).hover(function(event){
event.stopPropagation();// doesn't work.
console.log('Capture for hover in ' + current.tagName + '#'+ current.id +
' target is ' + event.target.id); },
function(event){
event.stopPropagation();
console.log('Capture for hover out' + current.tagName + '#'+ current.id +
' target is ' + event.target.id); });

});
});
</script>

<body id="greatgrandpa">
<div id="grandpa">
<div id="parent">
<div id="child"/>
</div>
</div>
</body>

最佳答案

.hover() 方法绑定(bind) mouseentermouseleave 事件的处理程序。当鼠标位于元素内时,您可以使用它简单地将行为应用于元素。

但是,如果您使用 mouseovermouseout 事件,当鼠标移入和移出元素及其后代时,这些事件将被触发。

参见http://jsfiddle.net/5yQY5/您的示例的另一种尝试。

关于jquery - 嵌套元素悬停 handle ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15490859/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com