Home > Web Front-end > JS Tutorial > jQuery sets keyboard to switch text box focus

jQuery sets keyboard to switch text box focus

php中世界最好的语言
Release: 2018-04-26 14:11:49
Original
1736 people have browsed it

This time I will bring you jQuerySet the keyboard to switch the focus of the text box. What are the precautions for jQuery to set the keyboard to switch the focus of the text box. The following is a practical case. Let’s take a look. one time.

<script src="http://yige.org/static/js/j.js"></script>
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();
        }
    });
});
Copy after login

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to the php Chinese website Other related articles!

Recommended reading

How to use Mobile to control the get request when the page returns

How to use the form component in the Mobile framework

The above is the detailed content of jQuery sets keyboard to switch text box focus. For more information, please follow other related articles on the PHP Chinese website!

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