用javascript在手机上显示虚拟键盘 [英] Show virtual keyboard on mobile phones in javascript

查看:159
本文介绍了用javascript在手机上显示虚拟键盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建我的网站的移动版本。网站的一部分会弹出一个带有文本输入的对话框。通常我会使用jQuery将焦点带到文本输入,但这不起作用。这是我正在尝试的:

I'm creating a mobile version of my site. There's a part of the site where a dialog pops up with a text input. Normally I would just use jQuery to bring focus to the text input, but that's not working. Here's what I'm trying:

$("#textinput").focus();
$("#textinput").click(); 
$("#textinput").trigger("tap"); //jQuery Mobile

它们似乎都不起作用。有任何想法吗?我一直在我的DroidX上测试它。我正在使用jQuery Mobile,但如果他们有帮助,我会对其他库开放。

None of them seem to work. Any ideas? I've been testing it on my DroidX. I'm using jQuery Mobile but I'm open to other libraries if they help.

推荐答案

你不能,至少不是在iOS(iPhone),我也相信Android。这是一个可用性问题,除非用户输入,否则不应该触发键盘(如果它是自动的,那就太烦人了)。

You can't, at least not in iOS (iPhone), and I believe Android as well. It's a usability issue that the keyboard should not be allowed to be triggered except by user input (it's just annoying if it's automatic).

我知道有几种方法解决这个问题:

There are a couple of ways I know of to get around this:


  • prompt()打开键盘

  • 如果从 .click()事件中触发 .focus() (例如,从打开对话框开始),键盘显示

  • prompt() opens the keyboard
  • If you trigger the .focus() from within a .click() event (e.g. from opening your dialog), the keyboard shows up

这篇关于用javascript在手机上显示虚拟键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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