当脚本动态地将div附加到正文时,如何克服IE错误 [英] how to overcome IE bug when dynamically attaching div to body from script
问题描述
更新:HTML格式不正确。这导致脚本出现在内部div中。请忽略这个问题。
UPDATE: the HTML was not well formed. This was causing the script to appear in inner div. Please ignore the question.
IE ver< 8有一个已知的错误(Internet Explorer不能显示页面)操作中止
如果脚本试图追加某些东西到上层块:
IE ver<8 has a known bug (Internet explorer cannot display the page. Operation aborted) If a script tries to append something to upper level block:
错误描述这里:
更新:我改写了这个问题并简化了例子:
Update: I rephrased the question and simplified the example:
错误发生在以下代码中:
The bug occurs in the following code:
[end of html file]
<script type="text/javascript" >
if (window.document.body){
var c_div = window.document.createElement('div');
window.document.body.appendChild(c_div);
}
</script>
</body>
问题:这似乎与我完全类似于example1 Method1在Microsoft解决方法(这里是链接)。怎么我还有bug?我在这里缺少什么?
Question: This seems to me exactly similar to example1 Method1 In Microsoft workaround (here is the link again). How come I still have the bug? What am I missing here?
推荐答案
在domready / onload事件处理程序中运行代码
Run your code in a domready/onload event handler.
这篇关于当脚本动态地将div附加到正文时,如何克服IE错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!