ios设备中,JS执行focus方法,无法调起键盘
问题背景:
移动端开发,有一个input输入框(默认输入框是disabled,不能编辑的),需要点击一个“修改”按钮,使input能编辑,并聚焦弹起软键盘。所以,在点击“修改”按钮的时候,JS执行focus()方法,来达到所要的效果,但在IOS设备上出了一些问题。
问题描述:
- android设备中,JS执行focus方法,能正常聚焦和弹出键盘;
- ios设备中,JS执行focus方法,不能弹出键盘;
解决方法:
再点击的“修改”按钮上绑定touchstart和click事件,touchstart事件中让input的disabled变为false,在click事件中执行focus方法
给input输入框,加一个清空图标,再点击图标时,input不失去焦点
JS阻止默认事件,通过在图标上添加onmousedown事件,并在该事件中阻止默认事件