场景:在ios手机上,点击input输入框,很难选中
分析后发现单击很难触发onClick事件,只有双击才会触发这个onClick事件
检查 是否加载了 fastclick 库,移动端一般都会安装这个库,区分双击和单击事件,一般情况下都是因为这个导致的,因此解决办法有两种:
1.去掉fastclick库
2.加一段代码:
if ('addEventListener' in document) { document.addEventListener('DOMContentLoaded', function() { if (FastClick) { FastClick.attach(document.body); } }, false); } // 解决ios 微信环境点击input无效 需要双击才生效 FastClick.prototype.focus = function(targetElement) { var length; // Issue #160: on iOS 7, some input elements (e.g. date datetime month) throw a vague TypeError on setSelectionRange. These elements don't have an integer value for the selectionStart and selectionEnd properties, but unfortunately that can't be used for detection because accessing the properties also throws a TypeError. Just check the type instead. Filed as