Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何知道浏览器为特定元素设置的光标样式_Javascript_Css - Fatal编程技术网

Javascript 如何知道浏览器为特定元素设置的光标样式

Javascript 如何知道浏览器为特定元素设置的光标样式,javascript,css,Javascript,Css,当使用“cursor:auto”CSS值时,如何知道浏览器为特定元素设置的光标样式 我想知道当悬停某个元素时,该元素的“auto”计算结果是什么 element.style.cursor只返回“auto”,而我想知道悬停元素时的计算值(“text”、“pointer”…) 在鼠标悬停侦听器中: let cursorStyle = window.getComputedStyle(e.target, null).cursor; console.log(cursorStyle); // outputs

当使用“cursor:auto”CSS值时,如何知道浏览器为特定元素设置的光标样式

我想知道当悬停某个元素时,该元素的“auto”计算结果是什么

element.style.cursor只返回“auto”,而我想知道悬停元素时的计算值(“text”、“pointer”…)

在鼠标悬停侦听器中:

let cursorStyle = window.getComputedStyle(e.target, null).cursor;
console.log(cursorStyle); // outputs "auto", not "text" when hovering a div / p with text

我想你根本没有机会。根据规范,游标的默认CSS值是
auto
(请参阅),这意味着浏览器可以自己使用它

您的脚本运行良好,并给出了正确的答案(“代码>光标”属性的值)。在自动模式下,浏览器在逻辑上不会更新属性(嗯,
auto
保持
auto
,不会每次都更改)

也许有一些黑客根据悬停的对象猜测光标,但实现起来会很痛苦