我正在使用以下代碼使用 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; } });
使用 Enter 鍵(包括 select2)在元素之間切換
守著一只汪
2022-06-16 09:55:05