1
function addRow(billingTable) 
{

    var table = document.getElementById(billingTable);

    var rowCount = table.rows.length;

    var row = table.insertRow(rowCount);
    var colCount = table.rows[0].cells.length;

    for (var i = 0; i < colCount; i++) 
    {
        var newcell = row.insertCell(i);

        newcell.innerHTML = table.rows[1].cells[i].innerHTML; 

// after this line the new cell is created but it also copies the
// value from the 1st row of the table.How can I set the value of
// this new cell to null or blank string ??


        switch(newcell.childNodes[0].type) 
        {
            case "text":
                newcell.childNodes[0].value = "";
                break;
            case "checkbox":
                newcell.childNodes[0].checked = false;
                break;
        }
    }
}
4

2 回答 2

1

而不是这条线,

newcell.innerHTML = table.rows[1].cells[i].innerHTML; 

你可以简单地写,

newcell.innerHTML = ""; 
于 2013-07-02T16:17:51.703 回答
0

新单元格由该行创建

var newcell = row.insertCell(i);

如果您希望新单元格的内容不与另一个单元格相同,则不要将其分配innerHTML给另一个单元格的innerHTML. 把它留空。

于 2013-07-02T16:17:20.963 回答