Home > Web Front-end > JS Tutorial > body text

jQuery实现回车键(Enter)切换文本框焦点的代码实例_jquery

WBOY
Release: 2016-05-16 16:49:54
Original
1076 people have browsed it

以下是实现方法:

复制代码 代码如下:


jQuery(function () {
    jQuery('input:text:first').focus();//直接定位到当前页面的第一个文本框
    var $inp = jQuery('input:text');//所有文本框
    $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();
        }
    });
});

 

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!