html focus 唤醒手机键盘,移动端 input 元素 focus 的时候调出键盘(自动触发 focus 事件的同时调出键盘)?...

安卓我目前没有遇到问题。

然后直接使用input.focus()是无法在ios中调起键盘的,因为ios中input元素的focus必须由事件触发。

此外,如果模拟了触摸事件,但是在setTimeout中延迟执行,也是不行的。这部分可以参考stackoverflow上的case:Mobile Safari Autofocus text field.

来自FastClick团队的大牛指出了IOS下input的获取焦点存在这样的问题:my colleagues and I found that iOS will only allow focus to be triggered on other elements, from within a function, if the first function in the call stack was triggered by a non-programmatic event. In your case, the call to setTimeout starts a new call stack, and the security mechanism kicks in to prevent you from setting focus on the input.

综上,要在ios中选中input并调起键盘,可以将focus调用包装在一个用户行为触发的事件中,如点击事件、表单onChange事件等。

解决方案

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值