Javascript IE中的currentStyle为空
我试图计算元素的当前样式:Javascript IE中的currentStyle为空,javascript,css,internet-explorer,Javascript,Css,Internet Explorer,我试图计算元素的当前样式: function cssIsLoaded(c) { if (window.getComputedStyle) { return window.getComputedStyle(c, null).display === "none"; } else if (c.currentStyle) { } return true; } (function() { var cssload = document.c
function cssIsLoaded(c) {
if (window.getComputedStyle) {
return window.getComputedStyle(c, null).display === "none";
}
else if (c.currentStyle) {
}
return true;
}
(function() {
var cssload = document.createElement("div");
cssload.className = "_css_loaded";
checkLoaded();
function checkLoaded() {
if (!cssIsLoaded(cssload)) setTimeout(function() {
checkLoaded();
}, 20);
else blalbalblbalbalablbal();
}
})();
IE未进入第二个条件,
c.currentStyle
为空。。。这是为什么?元素在添加到文档之前不会填充其currentStyle
属性,这有一定的意义:在元素添加到文档之前,浏览器无法知道将应用哪些现有样式规则。您在哪里调用cssIsLoaded()
?你通过的是什么元素?你能在创建一个例子吗?我正在传递一个我刚刚创建的DIV。在站点中加载函数的JS后,我调用该函数。(它是在我创建div之后调用的。请准确显示您是如何传递它的。这很可能是错误所在。