Javascript 财产';插入规则';和';删除规则';不存在于类型';样式表';

Javascript 财产';插入规则';和';删除规则';不存在于类型';样式表';,javascript,typescript,Javascript,Typescript,该代码用于检查浏览器是否支持CSS伪类。它在JavaScript中运行良好,但在Typescript中会出现错误。下面是typescript代码: var supportsPseudo = function(pseudoClass) { // Get the document stylesheet var ss = document.styleSheets[0]; // Create a stylesheet if one doesn't exist

该代码用于检查浏览器是否支持CSS伪类。它在JavaScript中运行良好,但在Typescript中会出现错误。下面是typescript代码:

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
的类型,
这是一份参考资料。

谢谢。这是我第一次使用typescript,你能告诉我怎么做吗?谢谢。成功了。我这样做了:
var ss=document.styleSheets[0]