0

歌剧让我发疯。处理 select(ion) 确实是一个挑战。我无法使用 Opera 禁用选择。通过鼠标或 Ctrl+A 进行选择仍处于启用状态。Opera 真的那么糟糕,还是有一些可用的解决方案或解决方法?


我的 CSS:

::selection {
  background: transparent;
} 

::-moz-selection {
  background: transparent;
}

* {
  user-select: none;
  -khtml-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  -o-user-select: none;            // for future? compatibility
  -webkit-user-select: none;
}

我的 JavaScript:

var elements = document.getElementsByTagName('*');
for (var i = 0; i < elements.length; i++) {
  elements[i].setAttribute('unselectable', 'on');
}

没有什么帮助。请指教。

示例:(如果您有 Opera 可用)转到小提琴,单击“结果”部分并按 Ctrl+A。

4

2 回答 2

0

阅读https://developer.mozilla.org/en/CSS/-moz-user-select user-select 在 Opera 上不可用。这同样适用于 Internet Explorer 版本 9 及以下版本。

http://help.dottoro.com/lhwdpnva.php描述了不可选择如何仅在 Internet Explorer 和歌剧中有效,但仅适用于从元素内开始的选择。之前开始,或者我猜是Ctrl+A,你仍然可以选择它。根据这篇文章,这同样适用于 Internet Explorer。

然而,我一直无法尝试。

于 2012-07-14T22:39:43.307 回答
0

请尝试使用此脚本:

<script type="text/javascript">
    disableSelection(document.body) 
</script>

<script type="text/javascript">
    function disableSelection(target){
        if (typeof target.onselectstart!="undefined") //IE route
            target.onselectstart=function(){return false}
        else if (typeof target.style.MozUserSelect!="undefined") //Firefox route
            target.style.MozUserSelect="none"
        else //All other route (ie: Opera)
            target.onmousedown=function(e){if(e && e.target && e.target.tagName){if(/^(input|select)$/i.test(e.target.tagName)){return true;}}return false;}
        target.style.cursor = "default"
    }
</script>

小提琴:http: //jsfiddle.net/8qadwtzo/

于 2015-02-26T09:56:22.427 回答