[英]Property 'insertRule' and 'deleteRule' does not exist on type 'StyleSheet'
The code is used to check if a CSS Pseudo class is supported by the browser.该代码用于检查浏览器是否支持 CSS Pseudo 类。 It works fine in JavaScript but throws up errors in Typescript.
它在 JavaScript 中运行良好,但在 Typescript 中引发错误。 Below is the typescript code:
下面是打字稿代码:
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();
};
尝试使用这个CSSStyleSheet
接口来指定ss
的类型,这里有一个链接供参考。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.