admin管理员组

文章数量:1201571

My code is below:

$('.summaryT').keypress(function(e){
    if(e.which == 13){
        callajax();
        $(this).focusout();

    }
});

As you can see on the code above, When a user presses the enter key first callajax() is run(working fine). After that I want to focus out from the .summaryT input box, How can I achieve this?

My code is below:

$('.summaryT').keypress(function(e){
    if(e.which == 13){
        callajax();
        $(this).focusout();

    }
});

As you can see on the code above, When a user presses the enter key first callajax() is run(working fine). After that I want to focus out from the .summaryT input box, How can I achieve this?

Share Improve this question edited Sep 12, 2013 at 7:56 Damon 3,0127 gold badges25 silver badges28 bronze badges asked Sep 12, 2013 at 7:48 FriendFriend 1,34611 gold badges39 silver badges62 bronze badges
Add a comment  | 

4 Answers 4

Reset to default 16

Try this

$('.summaryT').keypress(function(e){
    if(e.which == 13){
        callajax();
        $(this).blur();    
    }
});

Since AJAX stands for asynchronous, you may want to call focusout() after the call successfully finished.

use the jquery blur() event

$('.summaryT').keypress(function(e){
    if(e.which == 13){
        callajax();
        $(this).blur();

    }
});

Here is the solution even if Mousetrap is activated

    $('.selectorClass').keypress(function(e)
    {
        if(e.which == 13)
        {
            // 13 is a code to hit keyboard enter button
            alert('Enter is pressed');
        }
    });

    $('#selectorID').keypress(function(e)
    {
        if(e.which == 13)
        {
            // 13 is a code to hit keyboard enter button
            alert('Enter is pressed');
        }
    });

本文标签: javascriptJquery focus out after pressing enter keyStack Overflow