Firefox 中可以选择输入字段和文本区域,但没有其他内容可以选择?
我需要阻止用户在我的网络应用程序 UI 中选择元素,输入字段和文本区域中的文本除外。对于 Firefox,该技术似乎是使用此 css:
* { -moz-user-select: none; }
并且效果很好(已测试 Firefox 3.5.2),只是您无法在输入字段或文本区域中进行选择。
我尝试将其划分为
div,td,span,img { -moz-user-select: none; }
input,textarea { -moz-user-select: text; }
但是,如果输入字段位于 div、td 或 span 内部,则它是不可选的。似乎 -moz-user-select 属性也适用于所有子项,无论这些子项是否覆盖该设置。除了针对特定元素将其设置为更细粒度(且烦人)的级别之外,有谁知道解决此问题的方法吗?
注意这不是出于安全目的。我很乐意让用户查看源代码或高级用户关闭此功能。但是对于具有拖放功能的 Web UI,或者只是那些应该表现得像一般应用程序而不是像文档的 Web UI,能够意外选择文本确实很奇怪。对于大多数用户来说,这种情况经常发生。
I need to prevent users from selecting elements in my web app UI, except for text in input fields and textareas. For Firefox, the technique seems to be to use this css:
* { -moz-user-select: none; }
And that works well enough (tested Firefox 3.5.2), except that you cannot then select within input fields or textareas.
I tried dividing it into
div,td,span,img { -moz-user-select: none; }
input,textarea { -moz-user-select: text; }
however, if the input field is inside of a div, td, or span, it is not selectable. It seems that the -moz-user-select property is applied to all children as well, no matter if those children override the setting. Does anyone know a way around this aside from setting this at a far more granular (and annoying) level for specific elements?
NOTE this is not for security purposes. I am fine having users view source or advanced users turning this off. But for web UI's with drag-and-drop functionality, or just those that are supposed to behave like an application in general rather than like a document, it is really weird to be able to accidentally select text. And it happens often for most users.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你正在为一场失败的事业而奋斗。如果我真的想从您的页面中选择文本,或者以某种方式获取它,我会的。
不过,关于你的问题。尝试在末尾添加 !important ,这样它看起来像这样:
You are fighting a lost cause. If I really want to select text from your page, or get it in some way, I will.
However, on to your question. Try adding !important to the end, so it looks like this: