为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

守着一只汪 2022-06-16 09:55:05
我正在使用以下代码使用 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;            }        });
查看完整描述

1 回答

?
jeck猫

TA贡献1909条经验 获得超7个赞

改变你keydownkeyup

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

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


查看完整回答
反对 回复 2022-06-16
  • 1 回答
  • 0 关注
  • 184 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号