ipad 上的 JQuery focus() 方法
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5287342/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JQuery focus() method on the ipad
提问by JesseBuesking
Possible Duplicate:
iPad HTML Focus
可能重复:
iPad HTML 焦点
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?
有谁知道如何从 jquery 获取 focus() 方法以在 ipad 上工作,或者可能是一种解决方法?我想要做的是让键盘在网页上弹出,因为我有 jquery 捕获击键来执行事件。但是,如果页面上没有文本框,我不知道如何让键盘弹出。现在我在页面上有了文本框,我正在尝试使用 jquery 将焦点设置到文本框,以便键盘弹出。最重要的是,我将文本框样式设置为 display:none,以便焦点转到文本框但未看到,因此该功能似乎可以正常工作。但是,focus() 在 ipad 上坏了!谁能帮我?
回答by NeoNexus DeMortis
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, iluminhas 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.
下面,ilumin有一个很好的解决方案,但它不是唯一的。基本上,根据我的发现,只要您在用户事件(例如 mouseup 或任何触摸事件 [这可能是触摸设备的首选])内执行 .focus() 函数调用,那么你应该没有问题。
To an extent I understand why Apple made this limitation, but at the same time, it has made my work very challenging.
在某种程度上,我理解 Apple 为何做出此限制,但同时,它也让我的工作变得非常具有挑战性。
回答by halfpastfour.am
Unfortunately, you will only see the keyboard pop up when you focus in a text field. See this answer.
不幸的是,当您聚焦在文本字段中时,您只会看到键盘弹出。看到这个答案。
回答by ilumin
<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
它适用于我的项目。只需使用“mouseup”来捕获事件并“关注”输入