This is an HTML / CSS / JS (jQuery) iPad app. I've got a button, that slides down an input form. I'd like to focus the user on the input, and then launch the keyboard.
这是一个HTML / CSS / JS (jQuery) iPad应用程序。我想把用户的注意力集中在输入上,然后启动键盘。
This is what I'm working with, but doesn't work:
这就是我正在研究的东西,但不管用:
$('#myFormField').focus();
This does indeed focus the input, but fails to launch the keyboard. Is it just not possible (for security reasons or whatever)?
这确实能聚焦输入,但不能启动键盘。这是不可能的吗(出于安全原因或其他原因)?
Is there a way to force or simulate a user tapping the input (or anything for that matter)?
有没有办法强迫或模拟用户点击输入(或其他什么)?
Thanks!
谢谢!
5 个解决方案
#1
4
Maybe these links can help you:
也许这些链接可以帮助你:
-
http://4pcbr.com/topic/how_to_open_keyboard_on_ipad_with_js(not working anymore)http://4pcbr.com/topic/how_to_open_keyboard_on_ipad_with_js(不工作了)
-
http://jgestures.codeplex.com
#2
3
Try this
Tested on Safari iPhone 7 & iPhone 6 Plus, Android 4.4
在Safari iPhone 7和iPhone 6 Plus上测试,Android 4.4。
and it opened iOS virtual keyboard successfully when I touched the button.
当我点击按钮时,它成功地打开了iOS虚拟键盘。
condition
1) make a Button to trigger keypress event => $('.btn_abc')
1)创建一个按钮来触发按键事件=> $('.btn_abc')
2) make a text input tag, and set the ID to this element => $('#search_input')
2)创建一个文本输入标记,并将ID设置为该元素=> $('#search_input')
$( document ).ready(function() {
var focusTextField = function(){
console.log("focusElement");
};
var onKeypressHandler = function(){
console.log("* * * keypress event handler")
$('#search_input').blur().focus();
};
var onClickHandler = function() {
$('.btn_abc').trigger('keypress');
};
$('#search_input').bind('focus', focusTextField);
$('.btn_abc').bind('click', onClickHandler);
$('.btn_abc').bind('keypress', onKeypressHandler);
});
#3
1
Turn that button into an input field then instantly swap focus to the main input field. They keyboard will open and stay opened. Below is an example using a button like you asked, placing a transparent input field over the button the user clicks. Tested on an iPhone 4 (iOS 6/7) and an HTC Windows phone.
将该按钮转换为输入字段,然后立即将焦点切换到主输入字段。他们的键盘会打开并保持打开状态。下面是一个使用如您所要求的按钮的示例,在用户单击的按钮上放置一个透明的输入字段。在iPhone 4 (iOS 6/7)和HTC Windows手机上测试。
The input you want the user to focus on:
您希望用户关注的输入:
<input id="main" />
The button the user presses (with input field overlayed using css):
用户按下的按钮(使用css重叠输入字段):
<a>Button</a><input onfocus="FocusMain()" />
Swap focus instantly:
交换焦点立即:
function FocusMain()
{
$("#main").focus();
}
#4
0
This should do what you want:
这应该做你想做的:
$("#element").focus().click();
#5
0
Try:
试一试:
$('#element').blur().focus();
or if that does not work:
或者如果这不起作用:
$('#element').focus().blur().focus();
blur() eliminates the focus and focus() brings it back. For some reason, it works every time compared to focus() working once in a while on its own.
blur()消除焦点和焦点()让它回来。出于某种原因,它每次都是在自己的工作中进行一次比较。
#1
4
Maybe these links can help you:
也许这些链接可以帮助你:
-
http://4pcbr.com/topic/how_to_open_keyboard_on_ipad_with_js(not working anymore)http://4pcbr.com/topic/how_to_open_keyboard_on_ipad_with_js(不工作了)
-
http://jgestures.codeplex.com
#2
3
Try this
Tested on Safari iPhone 7 & iPhone 6 Plus, Android 4.4
在Safari iPhone 7和iPhone 6 Plus上测试,Android 4.4。
and it opened iOS virtual keyboard successfully when I touched the button.
当我点击按钮时,它成功地打开了iOS虚拟键盘。
condition
1) make a Button to trigger keypress event => $('.btn_abc')
1)创建一个按钮来触发按键事件=> $('.btn_abc')
2) make a text input tag, and set the ID to this element => $('#search_input')
2)创建一个文本输入标记,并将ID设置为该元素=> $('#search_input')
$( document ).ready(function() {
var focusTextField = function(){
console.log("focusElement");
};
var onKeypressHandler = function(){
console.log("* * * keypress event handler")
$('#search_input').blur().focus();
};
var onClickHandler = function() {
$('.btn_abc').trigger('keypress');
};
$('#search_input').bind('focus', focusTextField);
$('.btn_abc').bind('click', onClickHandler);
$('.btn_abc').bind('keypress', onKeypressHandler);
});
#3
1
Turn that button into an input field then instantly swap focus to the main input field. They keyboard will open and stay opened. Below is an example using a button like you asked, placing a transparent input field over the button the user clicks. Tested on an iPhone 4 (iOS 6/7) and an HTC Windows phone.
将该按钮转换为输入字段,然后立即将焦点切换到主输入字段。他们的键盘会打开并保持打开状态。下面是一个使用如您所要求的按钮的示例,在用户单击的按钮上放置一个透明的输入字段。在iPhone 4 (iOS 6/7)和HTC Windows手机上测试。
The input you want the user to focus on:
您希望用户关注的输入:
<input id="main" />
The button the user presses (with input field overlayed using css):
用户按下的按钮(使用css重叠输入字段):
<a>Button</a><input onfocus="FocusMain()" />
Swap focus instantly:
交换焦点立即:
function FocusMain()
{
$("#main").focus();
}
#4
0
This should do what you want:
这应该做你想做的:
$("#element").focus().click();
#5
0
Try:
试一试:
$('#element').blur().focus();
or if that does not work:
或者如果这不起作用:
$('#element').focus().blur().focus();
blur() eliminates the focus and focus() brings it back. For some reason, it works every time compared to focus() working once in a while on its own.
blur()消除焦点和焦点()让它回来。出于某种原因,它每次都是在自己的工作中进行一次比较。