键盘启动iOS 7时,不会捕获表单提交按钮事件 [英] Form submit button event is not captured when keyboard is up iOS 7

查看:175
本文介绍了键盘启动iOS 7时,不会捕获表单提交按钮事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用针对iOS的cordova构建网络应用程序。我有这种形式

I'm building an web app using cordova targeting iOS. I have this form

<form id="formID">

  <div class="row">
    <input type="text" name="something1" placeholder="something1" class="form-control" required maxlength="26" />
  </div>

  <div class="row">
    <input type="text" name="something2" placeholder="something2" class="form-control" pattern=".{6,6}" required />
  </div>

  <div class="row">
    <input type="submit" value="Submit" class="button btn-primary" />
  </div>

</form>

在我的javascript我有一个监听器的submit事件。

In my javascript I then have a listener for the submit event.

我的问题是,当键盘在iOS中显示时,单击提交按钮并不总是触发submit事件。有些时候它工作的前2次,但然后停止工作。任何人曾经跑过这个?

My problem is that when the keyboard is showing in iOS, clicking the submit buttons doesn't always trigger the submit event. Somethimes it works the first 2 times but then stops working. Anyone that has run in to this before?

由于现在您可能需要先点击键盘上的完成(使其消失),然后使用提交按钮。或者,单击提交按钮与键盘显示哪些将使keybpoard隐藏,然后再次单击提交。

As it is now you may need to first click "Done" on the keyboard (making it disappear) and then use the submit button. Or, click the submit button with the keyboard showing which will make the keybpoard hide and then click the submit again.

有什么想法吗?

EDIT

在iOS 6上可以正常工作,但在iOS 7提交按钮在前2次点击后不触发事件。

It works fine on iOS 6, but on iOS 7 the submit button doesn't trigger an event after the first 2 clicks.

推荐答案

所以我解决了我遇到的问题。如问题中所述,它适用于ios6和android。但对于ios7我注意到,当我增加了文本字段高于提交按钮的高度我得到了上面描述的错误。当我没有添加任何非默认样式,影响了提交按钮上方元素的高度工作。奇怪的权利。

So I solved the problem I was having. As stated in the question it worked fine for ios6 and android. But for ios7 I noticed when I increased the height of the text fields above the submit button I got the bug described above. When I didn't add any non-default styling that effected the height of the elements above the submit button worked. Weird right.

但之后我阅读了这个问题

因此,我没有提交按钮,让我的脚本等待提交事件触发,我将按钮更改为链接并监听了touchend事件。 Bam,它像一个魅力。

So instead of having a submit button and having my script wait for the submit event to fire, I changed the button to a link and listened for a touchend event. Bam, it worked like a charm.

$(document).on('touchend', 'form #button', function (e) {
    $('#formID').submit();
});

所以我让这个事件绕过并触发submit事件,点击键盘仍然触发提交功能。

So I let this event bypass and trigger the submit event so that clicking the "Go" button on the keyboard still trigger a submit function.

这篇关于键盘启动iOS 7时,不会捕获表单提交按钮事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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