如果让整个页面都禁止选择,可以使用下面的css
body{
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
如果希望指定元素禁止访问,请看下面的示例代码:
<!doctype html>
<html>
<head>
<style type="text/css">
*.unselectable {
-moz-user-select: -moz-none;
-khtml-user-select: none;
-webkit-user-select: none;
/*
Introduced in IE 10.
See http://ie.microsoft.com/testdrive/HTML5/msUserSelect/
*/
-ms-user-select: none;
user-select: none;
}
</style>
</head>
<body>
<div class="unselectable">
<p>这是很长的一段文本。啦啦啦啦啦啦</p>
</div>
</body>
</html>