【问题标题】:Jquery focus out after pressing enter key按下回车键后Jquery焦点消失
【发布时间】:2013-09-16 11:56:40
【问题描述】:

我的代码如下:

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

    }
});

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

【问题讨论】:

    标签: javascript php jquery html css


    【解决方案1】:

    即使 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');
            }
        });
    

    【讨论】:

      【解决方案2】:

      使用 jquery blur() 事件

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

      【讨论】:

        【解决方案3】:

        试试这个

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

        【讨论】:

          【解决方案4】:

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

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2019-06-05
            • 2011-10-04
            • 1970-01-01
            • 1970-01-01
            • 2014-08-04
            • 2014-06-08
            相关资源
            最近更新 更多