English 中文(简体)
Opera 10.62和IE9是否有用户选择?
原标题:Is there user-select for Opera 10.62 and IE9?

我一直试图为Opera 10.62和IE9应用用户选择,但没有成功。我不能/不会用<code>preventDefault()</code>的JavaScript绑定事件,因为有太多地方要设置为不可选择,而且我仍然需要在几个地方保留选择。事实上,我希望整个文档的默认行为是不可选择的,为此,我在样式表中设置了以下内容:

* {
    -o-user-select: none;
    -webkit-user-select: none;
    -moz-user-select: -moz-none;
    -khtml-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

Firefox 4、Chrome 7和Safari 5的一切都很好。只有IE9和Opera 10.62没有像我希望的那样工作。有什么想法吗?

附言:我的目标是现代浏览器。

最佳回答

Did you try using ::selection {color:currentColor;background:transparent}?
For Firefox you can use ::-moz-selection.

https://developer.mozilla.org/En/CSS/::selection
http://msdn.microsoft.com/en-us/library/ff974109(v=VS.85).aspx
http://reference.sitepoint.com/css/pseudoelement-selection


// update //
There s also the unselectable property.
问题回答

您可以使用-webkit用户选择的组合:none-moz用户选择:无和特定属性unselected=“on”,如我在此处所述:

如何使HTML页面上的文本不可选择

user select不是标准的CSS3属性,这就是为什么没有user select或-o user-select或-ms user select。它曾经在旧的用户界面规范中,但被基本UI规范所取代。除非将其重新添加到规范中,否则任何一个浏览器都可能永远无法实现它。

用户选择是一种行为而不是一种风格,因此最好使用JavaScript。正如Knu上面提到的,您可以使用不可选择。

使用jquery:

$( .element ).mousedown( function(e) {
    e.preventDefault();
});

但是您可能需要将它同时添加到元素和它的容器中。

-ms用户选择:无;

现在似乎运行良好(IE 10/11)





相关问题
Image rendered with wrong colors in IE8

I have a gradient image as a PNG (no transparency) in a web-page. By taking a screenshot of Chrome showing the page and cropping the image from the page, I see the exact same colors are drawn as the ...

Determine Mobile Internet Explorer version

I need to determine the version of Mobile Internet Explorer on a Windows Mobile 6.1 device. So that I can report the same user-agent string as is being used by Mobile Internet Explorer. The user-...

CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

Internet Explorer only part loading JavaScript/CSS

I m having trouble with my local development environment where IE (6 through to 8) is only part loading JavaScript/CSS files. It throws random errors at random places in jquery.min.js every time I ...

IE doesn t run Javascript when you click back button

I ve built a shop with tons of JS running. One of the pieces of the cart, is a zip code field which is required to calculate shipping cost. This works fine going through the cart. Now clicking ...

热门标签