document.getElementById("tt").parentElement.appendChild(span);//

解决方案 »

  1.   

    执行顺序有问题,加个defer就可以了,还有怎么可以给文本对象在加span对象呢,改成下面的就可以执行了
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>无标题文档</title>
    </head>
    <script language="javascript" defer>
    var span = document.createElement("SPAN");
    span.id = "__ErrorMessagePanel";
    span.style.color ="red";
    document.getElementById("dd").appendChild(span);//这句出错了!!!
    span.innerHTML = "* 旧密码不正确";
    </script>
    <body>
    <table width="500" height="36" border="0" cellpadding="0" cellspacing="0">
      <tr id="pp">
        <td id="dd"><input name="tt" type="text" id="tt" />
           </td>
      </tr>
    </table>
    </body>
    </html>
      

  2.   

    <SCRIPT FOR=window EVENT=onload LANGUAGE="JavaScript">
    </script>
      

  3.   

    不好意思,应该是document.getElementById("tt").parentNode.appendChild(span);但是现在提示缺少对象,换了parentElement也一样
      

  4.   

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>无标题文档</title>
    </head>
    <SCRIPT FOR=window EVENT=onload LANGUAGE="JavaScript">
    var span = document.createElement("SPAN");
    span.id = "__ErrorMessagePanel";
    span.style.color ="red";
    document.getElementById("tt").parentElement.appendChild(span);//这句出错了!!!
    span.innerHTML = "* 旧密码不正确";
    </script>
    <body>
    <table width="500" height="36" border="0" cellpadding="0" cellspacing="0">
      <tr id="pp">
        <td id="dd"><input name="tt" type="text" id="tt" />
           </td>
      </tr>
    </table>
    </body>
    </html>测试后ok ie6下
      

  5.   

    果然加了<SCRIPT FOR=window EVENT=onload LANGUAGE="JavaScript">就好了。高手能解释一下为什么吗?
      

  6.   

    上面已经说了,执行顺序问题,用了上面的代码相当于把中间的代码加到
    window.onload事件中,也就是页面加载完毕的时候,而用你的代码,还没执行到tt对象的时候,你就调他,当然找不到了
      

  7.   

    hbhbhbhbhb1021(天外水火(我要多努力))已经解释了....
      

  8.   

    有道理啊。现在发现javascript区很热门啊,高手也很热心。我好要好好学啊。