gpt4 book ai didi

jQuery 隐藏显示 id

转载 作者:搜寻专家 更新时间:2023-10-31 22:14:32 24 4
gpt4 key购买 nike

HTML

<ul id="menüü">  
<li id="meist">
<p><a href="meist.html">Meist</a></p>
</li> </ul>


<div id="submenu">
<ul id="submeist">
<li class="asi1">
Asi 1
</li>
<li class="asi2">
Asi 2
</li>
<li class="asi3">
Asi 3
</li>
</ul>
</div>

CSS

#meist {  
display: inline;
float:left;
width:180px;
height:50px;
color:#191919;
text-align:center;
overflow:hidden;
background:#990000;
-moz-border-radius-top-left: 50px;
border-top-left-radius: 50px;

}

#submeist
{
font-size:12px;
display:none;
}

#submeist .asi1
{
margin-left:70px;
}

#submeist .asi2
{
margin-left:25px;
}

#submeist .asi3
{
margin-left:25px;
}

JS

$("#meist").mouseout(function () { 
$("#submeist").hide();
return false;
});

$("#meist").mouseenter(function () {
$("#submeist").show();
return false;
});

我又来这里学习和了解如何在鼠标悬停在“meist”时显示“submeist”。我已经学习了一些 jQuery 的非常基础知识,但不知何故这段代码不起作用。非常感谢您的帮助,如果可能的话,请多多评论 :)

最佳答案

你应该使用 mouseleave而不是 mouseOut因为即使将鼠标悬停在 a 上也会触发 mouseOut或 p在里面 #meist .

$(function(){
$("#meist").mouseleave(function () {
$("#submeist").hide();
return false;
});

$("#meist").mouseenter(function () {
$("#submeist").show();
return false;
});
});

Demo

来自 Doc

The mouseleave event differs from mouseout in the way it handles event bubbling. If mouseout were used in this example, then when the mouse pointer moved out of the Inner element, the handler would be triggered. This is usually undesirable behavior. The mouseleave event, on the other hand, only triggers its handler when the mouse leaves the element it is bound to, not a descendant. So in this example, the handler is triggered when the mouse leaves the Outer element, but not the Inner element.

事件对是:

mouseover-mouseout

mousenter-mouseleave (悬停)

关于jQuery 隐藏显示 id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16901471/

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