繁体   English   中英

按下回车键后,Jquery将注意力集中

[英]Jquery focus out after pressing enter key

我的代码如下:

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

    }
});

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

试试这个

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

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

使用jquery blur()事件

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

    }
});

即使激活了Mousetrap,这里也是解决方案

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM