【问题标题】:Android keyboard not opening for input tag bound to touchstartAndroid键盘未打开绑定到touchstart的输入标签
【发布时间】:2012-08-10 09:40:41
【问题描述】:

标记:

<section id="loginform">
  <input type="text" id="username" placeholder="Username"/>
  <input type="password" id="password" placeholder="Password"/>
  <input type="submit" value="login" id="login"/>
</section>

JavaScript:

$('#loginform #username').bind('touchstart', function(e) {
   $(this).focus()
})
$('#loginform #password').bind('touchstart', function() {
   $(this).focus()
})

在 Android (4.0) 上打开此站点并单击用户名或密码的输入字段,没有弹出键盘...如果我执行如下代码:

$('#loginform #username').bind('touchstart', function(e) {
    alert("android why u no keyboard show!?")
    $(this).focus()
})

然后键盘会弹出...警报e.isDefaultPrevented()返回false

你知道什么是错的吗?

谢谢

【问题讨论】:

    标签: javascript android jquery


    【解决方案1】:

    试试这个:您可以将此代码放在document.ready 或其他地方

    $('#username').bind('touchstart', function(e) {
       $(this).focus()
    })
    $('#password').bind('touchstart', function() {
       $(this).focus()
    })
    

    其中可能有一些事件正在冒泡。

    【讨论】:

    • 没用... :( 想知道为什么 alert() 有帮助,如果我把它放在那里键盘会弹出...
    • 我想尝试添加一些时间间隔延迟,这将有助于它像 settimeout 函数一样工作。浏览此链接electrictoolbox.com/using-settimeout-javascript
    猜你喜欢
    • 1970-01-01
    • 2017-09-30
    • 2022-11-10
    • 1970-01-01
    • 2014-08-24
    • 1970-01-01
    • 1970-01-01
    • 2015-12-01
    • 1970-01-01
    相关资源
    最近更新 更多