Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

This is my script file. I am call my div id="AppContainer " in this script when press enter.This code is working on only chrome browser but not working in other browser.What is the problem?

  HTML:
    <div id="AppContainer">
    <input type="text">
    <input type="text">
    </div>

    <script type='text/javascript'>
    $(document).ready(function(){
        $('#AppContainer input').keydown(function(e){
         if(e.keyCode==13){       

            if($(':input:eq(' + ($(':input').index(this) + 1) + ')').attr('type')=='submit'){// check for submit button and submit form on enter press
             return true;
            }

            $(':input:eq(' + ($(':input').index(this) + 1) + ')').focus();

           return false;
         }

        });
    });
    </script>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
182 views
Welcome To Ask or Share your Answers For Others

1 Answer

You may try this:

$(function () {
    $('#AppContainer').on('keydown', 'input:text', function (e) {
        if (13 === e.which) {
            e.stopPropagation();
            $(this).next('input:text').focus();
        }
    });
});

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...