[使用Enter键包括select2的元素来制表

问题描述 投票:0回答:1

我正在使用以下代码使用Enter键在表单元素之间进行制表。问题是此代码跳过了select2元素。

        $('body').on('keydown', 'input, select', function(e) {
            if (e.key === "Enter") {
                var self = $(this), form = self.parents('form:eq(0)'), focusable, next;
                focusable = form.find('input,a,select,button,textarea').filter(':not([disabled]):not([tabindex="-1"]):visible');
                next = focusable.eq(focusable.index(this)+1);
                if (next.length) {
                    next.focus();
                } else {
                    //form.submit();
                }
                return false;
            }
        });
javascript jquery jquery-select2
1个回答
0
投票

keydown更改为keyup

  $('body').on('keyup', 'input, select', function(e)

原因是keydown已在select2库中用于选择项目的处理

© www.soinside.com 2019 - 2024. All rights reserved.