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 this 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).
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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.