Weird IE behavior: currentStyle returns null

2019-04-29 11:10发布

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条回答
ら.Afraid
2楼-- · 2019-04-29 11:22

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.

查看更多
登录 后发表回答