0
点赞
收藏
分享

微信扫一扫

Html 设置或检索是否允许用户选中文本


设置或检索是否允许用户选中文本。

  • IE6-9不支持该属性,但支持使用标签属性 

onselectstart="return false;"

  •  来达到 

user-select:none

  • 直到Opera12.5仍然不支持该属性,但和IE6-9一样,也支持使用私有的标签属性 

unselectable="on"

  •  来达到 

user-select:none

  • 除Chrome和Safari外,在其它浏览器中,如果将文本设置为 

-ms-user-select:none;

  • ,则用户将无法在该文本块中开始选择文本。不过,如果用户在页面的其他区域开始选择文本,则用户仍然可以继续选择将文本设置为 

-ms-user-select:none;

  • 对应的脚本特性为userSelect

链接:点击打开链接

Example

HTML

<p>You should be able to select this text.</p>
<p class="unselectable">Hey, you can't select this text!</p>
<p>You should be able to select this text.</p>
<p class="unselectable">Hey, you can't select this text!</p>

CSS

.unselectable {
  -moz-user-select: none;
  -webkit-user-select: none;
  -ms-user-select: none;
  user-select: none;

.unselectable {
  -moz-user-select: none;
  -webkit-user-select: none;
  -ms-user-select: none;
  user-select: none;

}

举报

相关推荐

0 条评论