如何检查是否支持光标样式

Dan*_*Fox 4 javascript css mouse-cursor

如何使用JavaScript检查是否cursor:none支持?

Rob*_*b W 10

只需创建一个元素,设置属性,并检查该属性是否仍然存在.

function isCursorNoneSupported() {
    var a = document.createElement("a");
    a.style.cursor = "none";
    return a.style.cursor === 'none';
}

if ( isCursorNoneSupported() ) {
    alert("cursor:none is supported!");
} else {
    alert("cursor:none is not supported :(");
}
Run Code Online (Sandbox Code Playgroud)

要查看哪些浏览器支持cursor:none,请查看:cursor浏览器兼容性

  • @refhat` ===`是一个身份运算符.在这种情况下,无论你是使用`=='还是`===`都没关系,因为两个对象都是一个字符串.有关`===`vs` ==`的更多详细信息,请参阅[JavaScript === vs ==:我使用哪个"相等"运算符是否重要?](http://stackoverflow.com/questions/359494/ JavaScript的VS-确实-IT-物质-其中相等的操作员-I-使用) (2认同)