移动端禁止长按选择

方式一:简单粗暴

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

Tips:基本可以禁止所以浏览器的长按选择(UC浏览器除外)。另外该方法是禁止所以标签的选择,如果页面中存在 input 或 textarea 等输入标签则不适用该方法,因为IOS系统中无法激活输入标签。

方式二:优化

*:not(input){ user-select:none; -webkit-user-select:none; }

Tips: 如果页面中只有 input / textarea 中的一个,则可以使用该方法。有人会说为什么不用 *:not(input, textarea){ xxx },因为在安卓系统中无效。

方式三:进一步优化

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

input,textarea{ user-select:text; -webkit-user-select:text; }

Tips:最后是比较通用的方法。


版权声明:本文为xjun0812原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。