IE8 下的Js错误HTML Parsing Error...

2019-12-25,,

网页错误详细信息


用户代理: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; QQDownload 551; SLCC2; .NET CLR 2.0.50727)
时间戳: Wed, 12 Aug 2009 07:02:03 UTC



消息: HTML Parsing Error: Unable to modify the parent container element before the child element is closed (KB927917)
行: 0
字符: 0
代码: 0


今天调试一段JS代码出现这个状况..在火狐 IE7 和IE6下都正常...郁闷,在网上搜索了一下相关资料 一般错误都是指所指定的标签没有加载完就是用该对象....


检查了代码 从表面上看没有什么问题


如下


<body>


<script language="javascript">


 var bgObj = document.createElement("div"); 
        bgObj.style.cssText = "position:absolute;left:0px;top:0px;width:"+iWidth+"px;height:"+Math.max(document.body.clientHeight, iHeight)+"px;filter:Alpha(Opacity=30);opacity:0.3;background-color:#000000;z-index:101;"; 
        document.body.appendChild(bgObj);
</script>
</body>


其实 仔细检查出来就发现 这段代码会在body没有加载完毕之前运行....


问题就出在这里....


所以 代码只能放在波电压外面去执行


<body>


</body>


<script language="javascript">


 var bgObj = document.createElement("div"); 
        bgObj.style.cssText = "position:absolute;left:0px;top:0px;width:"+iWidth+"px;height:"+Math.max(document.body.clientHeight, iHeight)+"px;filter:Alpha(Opacity=30);opacity:0.3;background-color:#000000;z-index:101;"; 
        document.body.appendChild(bgObj);
</script>


这样OK没问题了...看来IE 的逻辑性越来越强了.....可能以前很多代码都会出现这种问题咯

《IE8 下的Js错误HTML Parsing Error....doc》

下载本文的Word格式文档,以方便收藏与打印。