移動端input 無法擷取焦點的問題

來源:互聯網
上載者:User

標籤:issues   複製   ogr   port   需要   NPU   文章   技術分享   tac   

下午遇到一個問題,移動端的input都不能輸入了,後來發現是

-webkit-user-select :none ;

在移動端開發中,我們有時有針對性的寫一些特殊的重設,比如:

* {      -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。

如果網站不需要阻止使用者的選擇內容的行為就可以使用如下樣式:

  * {    -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 .

所以,最好把它也加上。

最終的代碼:

[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

移動端input 無法擷取焦點的問題

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.