Home >Web Front-end >JS Tutorial >jQuery code example to implement the Enter key (Enter) to switch the focus of the text box_jquery

jQuery code example to implement the Enter key (Enter) to switch the focus of the text box_jquery

WBOY
WBOYOriginal
2016-05-16 16:49:541129browse

The following is the implementation method:

Copy the code The code is as follows:


jQuery(function () {
jQuery('input:text:first').focus( );//Directly locate the first text box of the current page
var $inp = jQuery('input:text');//All text boxes
$inp.bind('keydown', function ( e) {
var key = e.which;
if (key == 13) {
e.preventDefault();
var nxtIdx = $inp.index(this) 1;
            jQuery(":input:text:eq(" nxtIdx ")").focus();
                                                                                                                                                                  jQuery(":input:text:eq(" nxtIdx ")").focus();
                                  

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn