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

jQuery sets keyboard to switch text box focus

php中世界最好的语言
php中世界最好的语言Original
2018-04-26 14:11:491687browse

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();
        }
    });
});

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!

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