<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
<!--
#apDiv1 {
position:absolute;
left:98px;
top:78px;
width:321px;
height:130px;
z-index:1;
background-color: #006666;
}
-->
</style>
</head>
<script type="text/javascript">
document.getElementById("apdiv1").style.top=100+'px';
</script>
<body>
<div id="apDiv1"></div>
</body>
</html>这样的代码在IE6下ok,但在ie8或google下却不行!
该怎么办?

解决方案 »

  1.   

    有两个问题:
    1.代码出现的顺序不对,这段代码要出现在div后面才行。
    2.id是大小写敏感的。<script type="text/javascript">
    //或者在onload事件发生时执行,这样就不用考虑代码出现的顺序了。
    window.onload = function() { document.getElementById('apDiv1').style.top = 100 + 'px'; }
    </script>
      

  2.   

    顺序不对程序最基本的3种逻辑:
    1、顺序
    2、条件(分支)
    3、循环<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    <style type="text/css">
    <!--
    #apDiv1 {
        position:absolute;
        left:98px;
        top:78px;
        width:321px;
        height:130px;
        z-index:1;
        background-color: #006666;
    }
    -->
    </style>
    </head><body>
    <div id="apDiv1"></div><script type="text/javascript">
    // 从上往下解析,js 放div 下面就可以!
    document.getElementById("apdiv1").style.top=100+'px';
    </script></body>
    </html>
      

  3.   

    追问:
    xmlhttp.open(.......);
    xmlhttp.send(); document.getElementById("apdiv1").innerHTML=xmlhttp.responseText;返回的文字在IE6下OK,
    IE8不成功!
      

  4.   

    纠结了一会,还是给LZ个建议吧 呵呵
    1、代码格式化下贴出来多好 别人看了也舒服 
    2、上边两位解答了您的问题 还有问题的话请将源代码修改后贴出相关部分
       最起码<div id="apDiv1"></div> 
       document.getElementById("apdiv1").style.top=100+'px';
    这两个不一致啊 我猛的一看都不知道您说的div是哪个
    想解决该问题 还得晒出代码来 呵呵