css 让文字不被选中 之 -moz-user-select 属性

最近开发一些项目遇到一些问题,搜了一些资料现在贴出来

以备后患

以下内容来自互联网:原文地址:http://wind6266.blog.163.com/blog/static/6710907200810401320241/

同事要做一个类似google calender的东西给客户,但是因为选中了旁边的文字,而使得javascript事件失效,onmousedown事件在选中文字的情况下,点击鼠标左键,不会有反应,相反把鼠标放开,本应该执行onmouseup事件,此时却执行了onmousedown事件。(请各位网友指点)


        他问我怎么办,我直觉就是让文字不被选中,应该有一个css属性进行控制,结果网上查了没有,查看google calender,

        他在ie下也能选中文字,但是选中其他列表,不会选中文字,原来它是在不同div中,属于不同的范围,而同事是放在同一个table中,当然会选中。

        而在firefox下,文字不会被选中,查看google calender的css,原来还有-moz-user-select这个属性,很好玩!

       最后采用一个了js方法,即onselectstart=function{return false;},不让页面进行选择,呵呵,这是很多网站不让复制采用的方法。


Summary

-moz-user-select is a Mozilla property extension to CSS that is used to determine whether or not an element may have its content selected.

Media: interactive

Possible uses include: prohibiting the selection of content in attempts to reduce blatant copying.

Syntax

TARGET_ELEMENT{-moz-user-select: none;}

Legal Values

ValueDescription
inheritInherit the value from the parent element.
noneNone of the content may be selected.
textOnly the text within the element may be selected.
elementA single element may be selected (from many).
elementsMultiple elements may be selected.
allThe contents must either be selected in entirety or none at all.
toggleThe contents are selected "following a standard toggling content model" [1].
tri-stateunknown
-moz-allunknown

Usage Examples

This sample code provides a simple "Hello, World!" text which prevents the user from selecting the content:

<span style="-moz-user-select: none;">
Hello, World!
</span>

Notes

This property is similar to the user-select property of CSS3.

When the 'none' value was applied to a heading element the content could still be selected.

According to the W3C, the "User agent's default style sheet may override this value. For example, user agents typically do not allow selection of the contents of a BUTTON element. [2] As the -moz-user-select was designed to mimic the user-select property, the same applies.

Specification Conformance

Doesn't conform to CSS standards; A Mozilla CSS Extension.

Browser Compatibility

Netscape 6+
Mozilla 0.6+
Firefox 1.0+

See Also

-moz-user-focus
-moz-user-input
-moz-user-modify

转载于:https://www.cnblogs.com/winxiang/archive/2012/01/11/2319220.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值