日期:2014-05-16  浏览次数:20326 次

为什么这种方法不能给表格单元格赋值
为什么这种方法不能给表格单元格赋值:
    假设两个表格样式一模一样。代码如下:   不知道问题在哪?
function   replaceContent()   {          
              var   table1   =   document.getElementById( "Method_Info ");
              var   table2   =   document.getElementById( "Note_Info ");    
              for   (i=0;   i   <   table1.rows.length;   i++)   {
for   (j=0;   j   <   table1.rows(i).cells.length;   j++)   {    
        var   Str1=table2.rows(i).cells(j).firstChild.nodeValue;
        table1.rows(i).cells(j).firstChild.nodeValue=Str1;
}
              }
      }

------解决方案--------------------
for (j=0;j <table1.rows(i).cells.length;j++){
var Str1=table2.rows(i).cells(j).innerText;
table1.rows(i).cells(j).innerText=Str1;
}
------解决方案--------------------
这种方式是可以的,除非你粗心大意写错了代码
var Str1=table2.rows(i).cells(j).firstChild.nodeValue;
这里的 "; "有问题,或许是别的地方的错误
------解决方案--------------------
楼上正解,还可以添加控件。table1.rows(i).cells(j).innerHtml=Str1;