需要使用javascript识别iOS编辑键盘中的“完成”按钮 [英] Need to identify the 'Done' button click in iOS edit keyboard using javascript

查看:427
本文介绍了需要使用javascript识别iOS编辑键盘中的“完成”按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

来自图像,是否可以使用javascript / jQuery识别iOS'完成'按钮单击事件? iOS键盘单击事件可以使用文本区域的'onkeypress'功能进行识别。

From the image, is it possible to identify the iOS 'Done' button click event using javascript/jQuery? The iOS keyboard click events can identify using 'onkeypress' function for the text-area.

推荐答案

如果该字段是表单,完成将触发表单的onsubmit事件。

If that field is part of the form, Done will trigger "onsubmit" event of the form.

一种方法是设置超时,该超时发生在每个表单元素的onblur(已分派)上,并且清除每个元素的onfocus。

One approach is to set a timeout, which occurs on every form element's onblur (which is dispatched) and is cleared on every element's onfocus.

jQuery中的简短示例作为解释:

Brief example in jQuery as an explanation:

var blurOccurred;

$("input")
.on("blur", function(evt) {
  blurOccurred = window.setTimeout(function() {
    alert('Done button clicked');
  }, 10);
})
.on("focus", function(evt) {
  window.clearTimeout(blurOccurred);
});

通过执行此操作,检测到单击完成,延迟时间为10毫秒。如果它只是导航到prev / next表单字段,则不会执行整个超时。

By doing this, clicking "done" is detected with 10ms delay. And if it's just navigating to prev / next form field, whole timeout won't be executed.

我希望这可以让你开始。

I'll hope this get you started.

编辑 event.relatedTarget 属性,点击完成时为空 - 否则它是设置焦点的输入元素。此外,它还可用于检测是否单击完成(或键盘已关闭)。

on iOS7 there is event.relatedTarget property, which is null when "done" is clicked - otherwise it's the input element where the focus is set on. Also this can be used for detecting whether done is clicked (or keyboard is closed).

这篇关于需要使用javascript识别iOS编辑键盘中的“完成”按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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