更改事件未在返回键上触发 [英] change event not fired on return key

查看:67
本文介绍了更改事件未在返回键上触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有jquery更改事件的文本框。

I have a textbox with a jquery change event tied to it.

$('#txtAccountNo').change(function(){
        $('label[for="txtAccountNo"]').append('<span class="support">loading...</span>')
    });

当文本框失去焦点时,即用户用鼠标点击它或使用它时,事件有效标签键。但是当按下返回键时,不会触发事件。有人可以帮我解决这个问题吗?

The event works when the textbox loses focus, ie the user clicks out of it with the mouse or uses the tab key. But when the return key is pressed the event is not fired. Can anybody help me resolve this please?

推荐答案

这是更改的标准行为事件。如果你想捕获每个 Enter 按,你需要使用 keypress 事件:

This is standard behaviour for the change event. If you want to capture each Enter press you need to use the keypress event:

$('#txtAccountNo').on('change keypress', function(e) {
  if (e.type == 'change' || (e.type == 'keypress' && e.which == 13)) {
    $('label[for="txtAccountNo"]').append('<span class="support">loading...</span>')
  }
});

这篇关于更改事件未在返回键上触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆