开发者

Weird IE behavior: currentStyle returns null

I am experiencing weird behavior in IE8 which appears to be an IE bug but I am not sure. When accessing currentStyle field from an element it returns null. If I view its properties in the watch window I can see that it is defined and I can view its members. It appears that if I call attributes before hand then it will return the correct currentStyle. I was wondering if anyone has seen thi开发者_开发技巧s behavior before and knows of some workarounds. This is happening when constructing the dojo grid. I also can not override this JavaScript behavior because it is buried deep in to an external Javascript library (dojo) and I do not have access to the function in the first place to override (function is defined in another functions scope).


The currentStyle object in IE is asynchronous. This means styles cannot be set and immediately queried. You must let IE act upon your manipulation once your JavaScript has finished making changes. You can setTimeout for 0 milliseconds, that will stick the function call on to a queue of some kind and IE will perform the DOM changes before calling the next bit of JavaScript.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜