我正在尝试计算元素的当前样式:
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属性,这是有道理的:在将元素添加到文档之前,浏览器无法知道哪些现有样式规则将应用于它.