.user-select-all { -webkit-user-select: all; /* Safari */ -moz-user-select: all; /* Firefox */ -ms-user-select: all; /* IE10+ */ user-select: all; /* Standard syntax */ } .user-select-none { -webkit-user-select: none; /* Safari */ -moz-user-select: none; /* Firefox */ -ms-user-select: none; /* IE10+ */ user-select: none; /* Standard syntax */ } .user-select-auto { -webkit-user-select: auto; /* Safari */ -moz-user-select: auto; /* Firefox */ -ms-user-select: auto; /* IE10+ */ user-select: auto; /* Standard syntax */ }
其中,“all”表示允许用户选中全部内容,“none”表示不允许选中任何内容,“auto”则为默认属性,允许用户选中内容。
应用以上代码后,用户在页面中进行鼠标拖选时,若选择的内容被指定为不可选中,则无法进行选择,反之则正常。除了提高页面可读性外,这一属性还可以用于保护文档的机密性,防止用户随意复制、粘贴内容等操作。