简体   繁体   English

在我的Cordova项目中,我想在iOS键盘上点击“完成”按钮触发一个功能(搜索功能)

[英]In my Cordova project, I want to trigger a function(search functionality) on iOS keyboard 'done' button click

在此输入图像描述

Is there anyway to solve this problem from native code. 无论如何,从本机代码解决此问题。

Please ignore below two solutions:- 请忽略以下两种解决方案: -

  1. If(window.event.keyCode == 13) . 如果(window.event.keyCode == 13)。 This is not working. 这不起作用。 Pressing the "Done" key does not fire a keyCode event. 按“完成”键不会触发keyCode事件。
  2. Keyboard will show and dismiss events. 键盘将显示和解除事件。 Since these event will call on screen touch. 由于这些事件将在屏幕上触摸。

As far as I analyzed, the good approach is to use Cordova keyboard plugin and listen for 'keyboardDidHide' event which will be fired on press of "Done" key. 据我分析,好的方法是使用Cordova键盘插件并收听'keyboardDidHide'事件,该事件将在按下“完成”键时触发。 But ensure to deregister this event once you are done with the desired operations on click of "Done" key. 但是,一旦完成了单击“完成”键所需的操作,请确保取消注册此事件。

Sample code snippet as follows: 示例代码段如下:

window.addEventListener('keyboardDidHide', function () {
    // logic which needs to be executed on click of "Done" key
    // Deregiter 'keyboardDidHide' event
});

More info on Cordova Keyboard Plugin is available on official github page . 有关Cordova Keyboard Plugin的更多信息,请访问官方github页面

$(document).keydown(function(e) {
   switch(e.which) {
      case 13: // enter button
          break;
      default: return; // exit this handler for other keys
   }
   e.preventDefault(); // prevent the default action (scroll / move caret)
});

You can check all the char code for keys here : http://www.cambiaresearch.com/articles/15/javascript-key-codes 您可以在此处查看密钥的所有字符代码: http//www.cambiaresearch.com/articles/15/javascript-key-codes

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

相关问题 需要使用javascript识别iOS编辑键盘中的“完成”按钮 - Need to identify the 'Done' button click in iOS edit keyboard using javascript 我想在 JavaScript 中显示我的特定搜索功能数组 - I want to show my specific array on search functionality in JavaScript 我的项目是虚拟钢琴我需要当用户单击键盘键钢琴按钮得到 hover 颜色 - my project is virtual piano I need when user click keyboard key the piano button get hover color 触发按钮单击jQuery的灯箱功能 - Trigger lightbox functionality on button click jQuery 我希望Android软键盘在合适的时刻有一个“完成”按钮WITHOUT JAVA - I want Android soft keyboard to have a “Done” button at the right moment WITHOUT JAVA jQuery通过done不工作触发点击功能 - jQuery trigger click function via done not working Angular - 如何在按钮点击时触发键盘事件? - Angular - How to trigger keyboard events on button click? Ionic/Cordova:无法以编程方式触发 iOS 键盘 - Ionic/Cordova: Can't trigger the iOS keyboard programmatically 需要链接或按钮单击以在我的Codeigniter网站上触发php函数 - Need a link or button click to trigger a php function on my Codeigniter site 我想在页面上加载多个图像时触发单个Javascript函数。 什么是最好的方式? - I want to trigger a single Javascript function when multiple images are done loading on the page. What will be the best way ?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM