<script language="javascript">
function addrow()
{
           var table = document.all("OrderDetails");
           var str="<tr><td>fdsfs</td></tr>";
  var item = table.getElementsByTagName("TBODY")
  item.insertAdjacentHTML("beforeEnd",str);
          }
          function getState()
{
  addrow();
  //add()
}
</script>
</HEAD>
<body MS_POSITIONING="GridLayout" onload="getState()">
<form id="Form1" method="post" runat="server">
<table id="OrderDetails"></table>
                  </form>
</body>为何不能插入一行呢?如果不是TABLE 而是其他元素就可以使用insertAdjacentHTML方法

解决方案 »

  1.   

    modify like this:
    <table id="OrderDetails">]
    <TBody></TBody>
    </table>
      

  2.   

    gyyshuai(师无横) 无敌了。比我想的方法好。一会我去实验下他说的行不行。不过我一般都写
    <div id=a></div>
    <script language=javascript>
    var str="<table><tr><td></td></tr></table>";
    a.htmlinner........
    </script>
      

  3.   

    TABLE/TBODY doesn't seem to support insertAdjacentHTML, the proper way to do it is like
    function addrow()
    {
               var table = document.all("OrderDetails"); var row = table.insertRow();
    var cell = row.insertCell();
    cell.innerText = "fdsfs";          }
      

  4.   

    我要在<TR>上加 onmouseover=highLight(this) 和 onmouseout=LoseLight(this)用 
    var item =document.createElement("tr")
    item.detachEvent("onmouseover",highLight)
    方法,不能传递参数啊
      

  5.   

    TABLE/TBODY 不支持insertAdjacentHTML方法你可以用table.insertRow(); 插入一行你是按思归大哥那样写 才出现:==报错:“该操作的目标元件无效”==吗
      

  6.   

    添加是用attachEvnet,除去才是detachEvent
    attachEvent后面的函数都是针对全局的,你给它传参数this,其实传的并不是这个tablerow,而是全局的window,<body>
    <table id="oTable"></table><script>
    function highlight(obj){
    obj.style.backgroundColor="pink";
    }
    function loselight(obj){
    obj.style.backgroundColor="red";
    }
    var oTableRow=document.getElementById("oTable").insertRow();
        //oTableRow.onmouseover=function(){highlight(this);};
          oTableRow.attachEvent("onmouseover",function(){highlight(oTableRow);});
        oTableRow.onmouseout=function(){loselight(this);};
    var oTableCell=oTableRow.insertCell();
        oTableCell.innerText="test";
        </script>