移动端input 没法获取焦点的问题

下午遇到一个问题,移动端的input都不能输入了,后来发现是html

-webkit-user-select :none ;web

在移动端开发中,咱们有时有针对性的写一些特殊的重置,好比:浏览器

* {
      -webkit - touch - callout: none;
    //-webkit-touch-callout:none; 阻止长按图片以后呼出菜单提示复制的行为
 //禁用Webkit内核浏览器的文字大小调整功能。 -webkit-text-size-adjust: none; 
  //避免点击a标签或者注册了click事件的元素时产生高亮
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
  //
    //禁止用户进行复制.选择.
    -webkit-user-select: none;
}

其中,-webkit-user-select :none ;会产生一些问题。
这是webkit内核浏览器下的一个bug,具体能够参考这篇文章:https://bugs.webkit.org/show_bug.cgi?id=82692网站


阻止了用户的选择内容行为,会致使一些“内容可编辑”标签没法正常使用,好比input、testarea。code

若是网站不须要阻止用户的选择内容的行为就可使用以下样式:htm

* {
    -webkit-user-select: text;
    -user-select: text;
}

另外一种方式:事件

*: not(input, textarea) {
    -webkit - touch - callout: none;
    -webkit - user - select: none;
}

user-select , can cause issues in elements with contenteditable="true" ,so better to add that too .图片

因此,最好把它也加上。element

最终的代码:开发

[contenteditable = "true"], input, textarea {
    -webkit-user- select: auto!important;
    -khtml-user-select: auto!important;
    -moz-user-select: auto!important;
    -ms-user-select: auto!important;
    -o-user-select: auto!important;
    user-select: auto!important;
}

本文内容大概就这么多,欢迎交流,欢迎反馈,若有错误,还请纠正,谢谢阅读。

附参考连接:
http://stackoverflow.com/questions/12812587/phonegap-styles-webkit-user-select-none-disabling-text-field



文/Scaukk(简书做者) 原文连接:http://www.jianshu.com/p/410866041619 著做权归做者全部,转载请联系做者得到受权,并标注“简书做者”。
相关文章
相关标签/搜索