javascript 如何更改网页上“文本选择”光标的外观或在所有主要浏览器中选择文本时禁用光标更改?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13935096/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to change appearance of "text-selection" cursor on webpages or disable cursor changing while a text is selected in all major browsers?
提问by Ji?í Zmrhal
I want to prevent the mouse cursor from changing when I move it over some text. Is this possible?
当我将鼠标光标移到某些文本上时,我想防止鼠标光标发生变化。这可能吗?
If not, I would like to change the appearance of text-selection
cursor - is it possible with css / javascript?
如果没有,我想更改text-selection
光标的外观- 是否可以使用 css / javascript?
回答by Alex Gill
Try this...
试试这个...
* {
-webkit-user-select: none;
}
*:active,
*:hover {
cursor: pointer;
}
回答by Peter Rasmussen
I think you are lookings for is the css property "cursor:default;"
- but this really depends on what exactly you are looking for. Example with a label:
我认为您正在寻找的是 css 属性"cursor:default;"
- 但这实际上取决于您正在寻找什么。带有标签的示例:
label{
cursor:default;
}
Depending on the cursor you want, you can change the value from "default"
to something else.
根据您想要的光标,您可以将值从更改"default"
为其他内容。
Here's a list of some of the values (Not all - but the most common are there): https://developer.mozilla.org/en-US/docs/CSS/cursor
这是一些值的列表(不是全部 - 但最常见的是):https: //developer.mozilla.org/en-US/docs/CSS/cursor
Remember you get different results depending on browser/OS.
请记住,根据浏览器/操作系统,您会得到不同的结果。
回答by Luke
Nobody feels like explicitly setting the cursor for each element, even if that only entails adding a class. That's a lot of hand work.
没有人愿意为每个元素明确设置光标,即使这只需要添加一个类。这是很多手工工作。
It would be wiser to:
更明智的做法是:
* {
cursor: inherit;
}
body {
cursor: default;
}
This will disable the text selection cursor for any element, but won't interfere with any other CSS or scripts that change the cursor-property for certain elements.
这将禁用任何元素的文本选择光标,但不会干扰更改某些元素的光标属性的任何其他 CSS 或脚本。