使用 Enter 键(包括 select2)在元素之间切换

我正在使用以下代码使用 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;

            }

        });


守着一只汪
浏览 185回答 1
1回答

jeck猫

改变你keydown的keyup  $('body').on('keyup', 'input, select', function(e)选择项目的原因keydown已在select2库中处理
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript