移動端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 著做權歸做者全部,轉載請聯繫做者得到受權,並標註「簡書做者」。
相關文章
相關標籤/搜索