安卓键盘未打开绑定到触摸启动的输入标签

Android keyboard not opening for input tag bound to touchstart

本文关键字:启动 触摸 输入 标签 绑定 键盘      更新时间:2023-09-26

Markup:

<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

知道可能出了什么问题吗?

谢谢

试试这个:你可以把这段代码放在document.ready或其他一些地方

$('#username').bind('touchstart', function(e) {
   $(this).focus()
})
$('#password').bind('touchstart', function() {
   $(this).focus()
})
可能其中有一些

事件正在冒泡。