有条件的onkeyup事件

发布于 2025-01-26 02:16:18 字数 329 浏览 1 评论 0原文

目前我正在使用以下内容:

document.onkeyup = function (data) {
    if (data.key == 'Escape') {
        ClosePlayerMenu()
    }
};

但是我有两个单独的菜单。适用于普通用户的PlayerMenu,以及工作人员的员工菜单。一切都起作用,但我不能两次使用当前代码,一个可以关闭播放器菜单,一个可以关闭员工菜单,因为这使得两个菜单不再关闭。因此,我试图使关键条件是,如果PlayerMenu开放, esc 将关闭它,如果员工菜单打开,它将关闭它。最好的方法是什么?

Currently I'm using the following:

document.onkeyup = function (data) {
    if (data.key == 'Escape') {
        ClosePlayerMenu()
    }
};

However I'm having two separate menus. A PlayerMenu for normal users, and a Staff menu for Staff members. Everything works but I can't use the current code twice, one to close the Player Menu and one to close the Staff menu as it makes one of the two menus no longer close. So I'm trying to make the key conditional that if PlayerMenu is open, ESC will close it, if Staff Menu is open it will close that. What would be the best approach?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文