javascript - 为什么 mouseover 和 mouseout 在 javascript 中不能正常工作?
问题描述
我有一个按钮
<button onmouseover="Lobby()" class="menuBtn"> Lobby </button>
然后我有一个 Lobby()
function Lobby()
{
document.getElementById("lobby").style.display = "block";
}
然后我就有了风格
#lobby
{
display: none;
height: 100%;
width: 16%;
}
我有一个 div
<div onmouseout="HideLobby()" class="submenupanel" id="lobby">
<button onclick="" class="l">Lobby</button>
<button onclick="GoToHelpDesk()" class="l">Information Center</button>
<button onclick="ProductDisplay()" class="l">Product Display</button>
</div>
另一个功能
function HideLobby()
{
document.getElementById("lobby").style.display = "none";
}
所以当我将鼠标悬停在大厅按钮上时,它应该显示 div。当我从 div 中移除鼠标时,它应该隐藏起来。但是当我悬停Information Center
或Product Display
div 隐藏时。为什么?
解决方案
onmouseleave
改为使用onmouseout
当鼠标指针离开任何子元素以及被选元素时触发 mouseout 事件。
mouseleave 事件仅在鼠标指针离开所选元素时触发。
function Lobby() {
document.getElementById("lobby").style.display = "block";
}
function HideLobby(event) {
document.getElementById("lobby").style.display = "none";
}
#lobby {
display: none;
height: 100%;
width: 16%;
}
<button onmouseover="Lobby()" class="menuBtn"> Lobby </button>
<div onmouseleave="HideLobby()" class="submenupanel" id="lobby">
<button onclick="" class="l">Lobby</button>
<button onclick="GoToHelpDesk()" class="l">Information Center</button>
<button onclick="ProductDisplay()" class="l">Product Display</button>
</div>
推荐阅读
- https - 使用 PWA 离线连接到 HTTPS 服务器
- c# - C# xUnit Mock SetUp 方法在测试运行时返回 null
- python - 在 python 中处理除以 0 错误和 nan 问题
- android - 在 web 视图中加载本地 HTML 文件时访问被拒绝错误
- html - 修复了全屏菜单选项 - 单击链接时,菜单切换应关闭
- json - 如何将 JSON 转换为结构
- python - 当我在 Django 中使用 Tweepy 时,芹菜不运行任务
- spring - Spring Soap 客户端 - 获取原始响应
- flutter - Flutter 远程记录 ELK filebeat
- push-notification - 没有负载的 FCM 推送通知到 Android 设备