使用Enter键(包括select2)在元素之间进行制表 [英] Tab through elements using Enter key including select2

查看:349
本文介绍了使用Enter键(包括select2)在元素之间进行制表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using following code to tab through form elements using enter key. Problem is that this code skip select2 elements.

        $('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;
            }
        });

推荐答案

将您的keydown更改为keyup

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

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

Reason is keydown is already handled in select2 library for choosing an item

这篇关于使用Enter键(包括select2)在元素之间进行制表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆