gpt4 book ai didi

javascript - getElementsByTagName 不是函数?

转载 作者:行者123 更新时间:2023-11-30 07:29:04 25 4
gpt4 key购买 nike

我实际上是在上一篇与我提出的问题相关的帖子中找到了这段代码,但是,尽管它看起来很简单,但我无法通过 doc.getElementsByTagName is not a function 错误。这是示例代码:

var addCssRule = (function() {
var addRule;

if (typeof document.styleSheets != "undefined" && document.styleSheets) {
addRule = function(selector, rule, doc, el) {
var sheets = doc.styleSheets, sheet;
if (sheets && sheets.length) {
sheet = sheets[sheets.length - 1];
if (sheet.addRule) {
sheet.addRule(selector, rule)
} else if (typeof sheet.cssText == "string") {
sheet.cssText = selector + " {" + rule + "}";
} else if (sheet.insertRule && sheet.cssRules) {
sheet.insertRule(selector + " {" + rule + "}", sheet.cssRules.length);
}
}
}
} else {
addRule = function(selector, rule, doc, el) {
el.appendChild(doc.createTextNode(selector + " {" + rule + "}"));
};
}

return function(selector, rule, doc) {
doc = doc || document;

var head = doc.getElementsByTagName("head")[0];
if (head && addRule) {
var styleEl = doc.createElement("style");
styleEl.type = "text/css";
styleEl.media = "screen";
head.appendChild(styleEl);
addRule(selector, rule, doc, styleEl);
styleEl = null;
}
};
})();

addCssRule("ol", "color:red", tinyMCE.Editor[0]);

我很确定代码是正确的。我想我误解了 tinymce 变量是如何传递的。你怎么看?

最佳答案

您传递给函数的第三个参数是 tinyMCE.Editor[0]那个getElementsByTagName函数吗?

关于javascript - getElementsByTagName 不是函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4610506/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com