点击两次后,无法在iOS上inputhtmlinput字段
我在iOS上遇到一个问题,我已经提出了一个小提琴:
http://jsfiddle.net/Hk56Q/
如果为任何触摸事件(touchstart / touchmove / touchend)添加了事件侦听器,如下所示:
function onTouch( e ){}; document.addEventListener( 'touchstart', onTouch, false );
导致input字段在iOS上具有以下行为:
- 第一次触摸:input获得焦点,用户可以正确input
- 随后的触摸(重点放在已经存在的字段):打字不再工作
在iPad和iPhone(模拟器和实际设备)上,我正在iOS 5,5.1和6上体验和testing此问题。
唯一的修复似乎是删除事件监听器来恢复input字段的正确行为(或实际上从不添加监听器):
document.removeEventListener( 'touchstart', onTouch);
我还注意到,如果页面上有多个iframe,并且其中一个将侦听器添加到其文档,则会打破其他iframe的input字段。
小提琴在我的Android手机上正确行事。
任何想法为什么会发生? 或者如何让触摸事件的全局自定义事件处理程序,而不会打破iOS上的input?
这是一个解决方法。 将焦点设置到窗口,然后返回到节点,超时:
function fixIpadTouch(node){ node.ontouchend=function(e){ if(document.activeElement===node){ window.focus(); setTimeout(function(){ node.focus(); },0); } } }
在我的情况下,Terry的答案的一个变种解决了这个移动Safari的错误(!!!)。 在这里,“#input”和这个代码是在iframe页面上:
var el = $('#input'); el.on('keydown', function() { window.focus() el.focus() });
这个错误以多种方式触发,但'keydown'可靠地通过。 这使得下一个“按键”也会到来。
jQuery Mobile 1.2.0应该是你需要的
certificate! 在勾选框之前:
在框中打勾后: