简体   繁体   English

jQuery在手机上按Enter或点击“确定”时会执行操作

[英]Jquery do action on pressing enter or hitting “OK” on mobile

I have an input field: 我有一个输入字段:

<input type="text" id="awesome-input" />

And I'd like to do an action when the user hits enter: 当用户点击回车时,我想执行一个操作:

$("#awesome-input").on('keydown',function(e){
  if(e.which == 13)
    console.log("did stuff!");
}

However , I'd also like to do the same action when a mobile user hits "ok" after typing on a touch screen. 但是 ,当移动用户在触摸屏上键入后单击“确定”时,我也想执行相同的操作。 My first thought was the submit event, but that only works if I wrap it in a form, which I'd rather not do. 我首先想到的是submit事件,但是仅当我将其包装成某种形式时才有效,而我不希望这样做。

事实证明,到目前为止,我尝试过的所有电话都会触发一次点击事件,其中e.which == 13 ,因此实际上它已经可以工作了。

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

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