ipad 上的 JQuery focus() 方法

发布于 2024-10-21 19:41:26 字数 405 浏览 1 评论 0原文

可能的重复:
iPad HTML 焦点

有谁知道如何从 jquery 获取 focus() 方法在 ipad 上工作,或者也许是一个解决方法?我想做的是让键盘在网页上弹出,因为我有 jquery 捕获击键来执行事件。但是,页面上没有文本框我不知道如何弹出键盘。现在我在页面上有了文本框,我尝试使用 jquery 将焦点设置到文本框,以便弹出键盘。除此之外,我将文本框样式设置为 display:none,以便焦点转到文本框,但看不到它,因此该功能似乎可以工作。然而,focus() 在 ipad 上被破坏了!谁能帮助我吗?

Possible Duplicate:
iPad HTML Focus

Does anyone know how to get the focus() method from jquery to work on the ipad, or perhaps a workaround? What I'm trying to do is to get the keyboard to pop up on a webpage since I have jquery capturing keystrokes to perform events. However, without a textbox on the page I don't know how to get the keyboard to pop up. Now that I have the textbox on the page, I'm trying to use jquery to set the focus to the textbox so the keyboard pops up. On top of this, I'm setting the textboxs style to display:none, so that the focus goes to the textbox but it's not seen, so the functionality appears to work. However, focus() is broken on the ipad! Can anyone help me?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

下雨或天晴 2024-10-28 19:41:26

不幸的是,显示键盘的唯一方法是在用户启动的事件期间。这是我最近一直在与自己斗争的事情。

下面,ilumin有一个很好的解决方案,但它不是唯一的。基本上,根据我的发现,只要您在用户事件(例如 mouseup 或任何触摸事件 [这可能是触摸设备的首选])内执行 .focus() 函数调用,那么你应该没有问题。

在某种程度上我理解苹果为什么做出这样的限制,但同时,这也让我的工作变得非常具有挑战性。

Unfortunately, the only way to get a keyboard to show, is during a user initiated event. This is something I've been fighting with myself as of late.

Below, ilumin has a good solution, but it's not the only one. Basically, from what I've found, as long as your are performing your .focus() function call inside of a user event (such as mouseup, or any of the touch events [which is probably preferred for a touch device]), then you shouldn't have a problem.

To an extent I understand why Apple made this limitation, but at the same time, it has made my work very challenging.

金橙橙 2024-10-28 19:41:26
<input>
<a href="#" class="label">Click</a>
$('.label').mouseup(function(){ $('input').focus(); });

它适用于我的项目。
“聚焦”输入

只需使用“mouseup”来捕获事件并通过 http://www.quora.com/Mobile-Safari-iPhone-or-iPad-with-JavaScript-how-can-I-launch-the-屏幕键盘

<input>
<a href="#" class="label">Click</a>
$('.label').mouseup(function(){ $('input').focus(); });

it work on my project.
just use "mouseup" to capture event and "focus" on input

via http://www.quora.com/Mobile-Safari-iPhone-or-iPad-with-JavaScript-how-can-I-launch-the-on-screen-keyboard

看海 2024-10-28 19:41:26

不幸的是,只有当您将焦点放在文本字段上时,您才会看到弹出的键盘。请参阅此答案

Unfortunately, you will only see the keyboard pop up when you focus in a text field. See this answer.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文