参考如下代码:
<html>
<head> <title>Test javascript method </title>
<script language="javascript">
var addTr = new function() {
this.addFun = function() {
var tableName = document.getElementById("mytable");
var thChar = tableName.insertRow(-1); var tdorder = thChar.insertCell(-1);
var tdname = thChar.insertCell(-1);
var tdtel = thChar.insertCell(-1); tdorder.appendChild(document.createTextNode("1"));   
tdname.appendChild(document.createTextNode("star"));
tdtel.appendChild(document.createTextNode("13880074647"));
}
}
window.onload = addTr.addFun;
</script>
<body><table id="mytable" border="1">
  <tr>
      <th>order </th>
      <th>name </th>
      <th>telephone </th>
  </tr>
 
</table></body> 

解决方案 »

  1.   

    呵呵,谢谢!
    你说的这种方式我会
    现在我就是想知道为什么在firefox下能正常运行上面的javascript,在IE下不行。
      

  2.   

    应该是 因为 TBODY 的原因吧,你插入的节点应该插到了TBODY之外了,fireFox我不清楚,但IE表格的主体节点要放到tbody中去才会显示出来.
      

  3.   

    不妨在IE中调用完你的函数后执行一下这句,就明了了.
    alert(tableName.outerHTML);
      

  4.   

    可以这样插.var tby = tableName.getElementsByTagName("tbody")[0];
        tby.appendChild(thChar);