首页 > 解决方案 > 同一页面上的多个模式上的相同按键

问题描述

我为页面上的所有模式窗口使用相同的按键。但是当多个弹出窗口同时打开时。我在一个模式上移动键,但它也开始在其余模式窗口上工作

$(document).keydown(function(e) {
            if ($tbody.find('.' + highlightClass).length) {

                if (e.which != 40 && e.which != 38) {
                    return false;
                }

                if (e.which == 40) { //down arrow
                    gotoNext();
                    e.preventDefault();
                } else if (e.which == 38) { //up arrow
                    gotoPrevious();
                    e.preventDefault();
                }
            }
        });

标签: jquery

解决方案


event.stopPropagation()请在调用之前尝试使用gotoPrevious()gotoNext()。我也会在打电话e.preventDefault() 之前尝试打电话gotoPrevious()gotoNext()

https://api.jquery.com/event.stoppropagation/


推荐阅读