代码用于检查浏览器是否支持CSS伪类。它在JavaScript中工作得很好,但是在类型记录中会抛出错误。下面是打字本代码:
var supportsPseudo = function(pseudoClass) {
// Get the document stylesheet
var ss = document.styleSheets[0];
// Create a stylesheet if one doesn't exist
if (!ss) {
var el = document.createElement("style");
document.head.appendChild(el);
ss = document.styleSheets[0];
document.head.removeChild(el);
}
// Test the pseudo-class by trying to style with it
var testPseudo = function() {
try {
if (!/^:/.test(pseudoClass)) {
pseudoClass = ":" + pseudoClass;
}
ss.insertRule("html" + pseudoClass + "{}", 0);
ss.deleteRule(0);
return true;
} catch (e) {
return false;
}
};
// Run the test
return testPseudo();
};发布于 2020-01-20 08:02:41
尝试使用这个CSSStyleSheet接口来指定ss的类型,下面是一个要引用的链接。
https://stackoverflow.com/questions/59818843
复制相似问题