我是靠谱客的博主 俏皮寒风,这篇文章主要介绍enter to next input,现在分享给大家,希望可以做个参考。

//使用jQuery,模拟按键TAB, 按回输键后,焦点自动跳到下一个input或selec

N年前在网上收藏的,当时没有记下原创地址。

((jQuery) => {
			// 模拟 Enter to Tab
			jQuery.extend(jQuery.expr[':'], {
				focusable: function(el, index, selector) {
					const $el = $(el);
					let result = $el.is('a, button, :input') && $el.is(":visible");
					if (result) {
						if ($el.attr("tabindex") < 0) {
							result = false;
						}
					}
					//return $(el).is('a, button, :input, [tabindex]');
					return result;
				}
			});
			$(document).on('keypress', 'input,select', function(e) {
				if (e.which == 13) {
					e.preventDefault();
					// Get all focusable elements on the page
					var $canfocus = $(':focusable');
					var index = $canfocus.index(document.activeElement) + 1;
					if (index >= $canfocus.length) index = 0;
					$canfocus.eq(index).focus();
				}
			});
		})(jQuery);

 

最后

以上就是俏皮寒风最近收集整理的关于enter to next input的全部内容,更多相关enter内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(114)

评论列表共有 0 条评论

立即
投稿
返回
顶部