在移动端禁用长按选中文本功能

在手机浏览器中,长按可选中文本,但如果在应用中,会给人一种异样的感觉,最好还是禁用此功能为上。

* {
-webkit-touch-callout:none;
-webkit-user-select:none;
-khtml-user-select:none;
-moz-user-select:none;
-ms-user-select:none;
user-select:none;
}

在iPhone中很好解决,只要给长按的div设置两个css:

-webkit-user-select: none;/*禁用手机浏览器的用户选择功能 */
-moz-user-select: none;

在没有特别定制过的安卓浏览器中也是可以的,但是在小米中就难了,因为小米长按页面中任何地方都会出现一个放大镜...然后我试了

window.ontouchstart = function(e) { e.preventDefault(); };

还是没效果,用小米测试,总是会选中目标div里面的文字...

转载:

http://www.cnblogs.com/iihe602/p/4269083.html

https://developer.mozilla.org/en-US/docs/Web/CSS/user-select

https://segmentfault.com/q/1010000002455346

原文地址:https://www.cnblogs.com/wawahaha/p/5058920.html