成品直播源码,设置文字不能被选中或解除文字无法被选中


方法一:JS

```csharp
if (typeof(element.onselectstart) != "undefined") {
// IE下禁止元素被选取
element.onselectstart = new Function("return false");
} else {
// firefox下禁止元素被选取的变通办法
element.onmousedown = new Function("return false");
element.onmouseup = new Function("return true");
}
```

IE下有 onselectstart 这个方法,通过设置这个方法可以禁止元素文本被选取。而firefox下没有这个方法,但可以通过css或一种变通的办法解决。
另一种方法是:

```csharp
ie:document.selection.empty()
ff:window.getSelection().removeAllRanges()
```

兼容的写法:

```csharp
window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
```

这种方法不但不影响拖放对象的选择效果,还能对整个文档进行清除。

方法二:CSS

```csharp
div {
-moz-user-select:none;
-webkit-user-select:none;
user-select:none;
}
```

以上就是成品直播源码,设置文字不能被选中或解除文字无法被选中, 更多内容欢迎关注之后的文章

 

posted @ 2022-04-20 14:14  云豹科技-苏凌霄  阅读(80)  评论(0)    收藏  举报