2016-08-04 119 views
-1

我使用硒来自动化测试浏览器应用程序,我需要一个JavaScript API来获取浏览器当前的光标样式,而不关心它在哪里。是否有一些API获取信息链接document.readstate如何使用javascript从浏览器中获取当前光标样式

+1

的可能的复制[检测游标类型(http://stackoverflow.com/questions/5304668/detect-cursor-type) –

+0

@RobinDorbell我认为这个问题是不是真的一个副本,因为OP询问(不关心它在哪里),而不是问题http://stackoverflow.com/questions/5304668/detect-cursor-type专门检查输入标记的光标输入,它使用selectionStart和selectionEnd,为我的理解OP的问题更为通用,不限于输入标签检测。 – GibboK

回答

3

以下脚本检测并打印页面上任何元素上的光标样式浏览器。

document.addEventListener('mouseover',function(e){ 
 
    var cursor = e.target.style.cursor; 
 
    console.log(cursor); 
 
},false);
span.crosshair { 
 
    cursor: crosshair; 
 
} 
 

 
span.help { 
 
    cursor: help; 
 
} 
 

 
span.wait { 
 
    cursor: wait; 
 
}
<p>Mouse over the words to change the cursor.</p> 
 
<span style="cursor:auto">auto</span><br> 
 
<span style="cursor:crosshair">crosshair</span><br> 
 
<span style="cursor:default">default</span><br> 
 
<span style="cursor:e-resize">e-resize</span><br> 
 
<span style="cursor:grab">grab</span><br> 
 
<span style="cursor:help">help</span><br> 
 
<span style="cursor:move">move</span><br> 
 
<span style="cursor:n-resize">n-resize</span><br> 
 
<span style="cursor:ne-resize">ne-resize</span><br> 
 
<span style="cursor:nw-resize">nw-resize</span><br> 
 
<span style="cursor:pointer">pointer</span><br> 
 
<span style="cursor:progress">progress</span><br> 
 
<span style="cursor:s-resize">s-resize</span><br> 
 
<span style="cursor:se-resize">se-resize</span><br> 
 
<span style="cursor:sw-resize">sw-resize</span><br> 
 
<span style="cursor:text">text</span><br> 
 
<span style="cursor:w-resize">w-resize</span><br> 
 
<span style="cursor:wait">wait</span><br> 
 
<span style="cursor:not-allowed">not-allowed</span><br> 
 
<span style="cursor:no-drop">no-drop</span><br>

相关问题