移动端input 无法获取焦点的问题
2019獨角獸企業重金招聘Python工程師標準>>>
下午遇到一個問題,移動端的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
文/Scaukk(簡書作者)
原文鏈接:http://www.jianshu.com/p/410866041619
著作權歸作者所有,轉載請聯系作者獲得授權,并標注“簡書作者”。
轉載于:https://my.oschina.net/songchunmin/blog/1561202
總結
以上是生活随笔為你收集整理的移动端input 无法获取焦点的问题的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 免杀之路
- 下一篇: 第六讲 使用第三方库及简单网页