有条件的onkeyup事件
目前我正在使用以下内容:
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论