【问题标题】:android enter key event not working in jquery [duplicate]android输入键事件在jquery中不起作用[重复]
【发布时间】:2018-10-31 06:57:47
【问题描述】:

jquery:

$('#search').keypress(function(e) {
  if (e.keyCode == 13) {
    $('#search').blur();
  }
});

HTML:

<div>
  <input id="search" type="text">
 </div>

我想detect enter jquery 中的key event mobile devices 就像android 一样按下键,一旦按下键,我需要blur输入框字段。

但我上面的 jquery 代码是not working。请帮我。

【问题讨论】:

  • 应该在 jQuery 中使用 e.which
  • 使用 keyup/keydown 事件代替 keypress。
  • @e.which 对我不起作用,然后只有我尝试使用 e.keycode

标签: javascript android jquery html


【解决方案1】:

重新编辑:

$('#search').on('keyup',function(e) { 
if (e.keyCode == 13) { 
$('#search').blur(); 
} 
});

【讨论】:

  • e.keyCode == 66 也不起作用
  • 你能在 if 阻塞之前记录你的键码吗?检查是否调用了按键?
  • 我正在尝试使用移动设备,那么我如何记录该事件?
  • 在你的html中添加一个标签,并在按键后设置keycode作为标签的值,可以吗?
  • 感谢您的帮助,我得到了解决方案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-02-10
  • 2021-07-29
  • 1970-01-01
  • 1970-01-01
  • 2013-07-30
  • 2013-01-25
  • 1970-01-01
相关资源
最近更新 更多