10

我的代码如下:

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

    }
});

正如您在上面的代码中看到的那样,当用户首先按下回车键时callajax()运行(工作正常)。之后我想从.summaryT输入框中集中注意力,我该如何实现呢?

4

4 回答 4

15

尝试这个

$('.summaryT').keypress(function(e){
    if(e.which == 13){
        callajax();
        $(this).blur();    
    }
});
于 2013-09-12T07:52:13.660 回答
1

由于 AJAX 代表异步,您可能希望focusout()在调用成功完成后调用。

于 2013-09-12T07:51:55.770 回答
1

使用 jquery blur()事件

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

    }
});
于 2013-09-12T07:52:27.900 回答
0

即使激活了捕鼠器,这也是解决方案

    $('.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');
        }
    });
于 2019-06-27T10:44:17.687 回答