开发者

Javascript cloneNode issue in FireFox

The JavaScript below works great in Internet Explorer, but doesnt work in FireFox.

It gets hung up at "NewField is undefined" which would be the line:

for (var i=0;i<NewField.length;i++)

That is the loop that will rename the form fields on that table row.

Here is where you can see the entire page http://www.sorenwinslow.com/CloneRowTest.asp

function CloneRows(TableRowId)
{
var NumRows = document.forms["TestForm"].NumRows.value;
NumRows++;
document.forms["TestForm"].NumRows.value = NumRows;
var RowToClone = document.getElementById(TableRowId);
var NewTableRow = RowToClone.cloneNode(true);
NewTableRow.id = TableRowId + NumRows ;
NewTableRow.style.display = "table-row";
var NewField = NewTableRow.all;
for (var i=0;i<NewField.length;i++)
{
    var theName = NewField[i].name;
    if (theName)
    {
        NewField[i].name = theName + NumRows;
    开发者_如何学Python}
}
var insertHere = document.getElementById(TableRowId);
insertHere.parentNode.insertBefore(NewTableRow,insertHere);
}


.all does generally not exist, only document.all, but it isn't even standard. Internet Explorer has some custom properties but you should not rely on them. You probably want .children:

var NewField = NewTableRow.children;

or .cells:

var NewField = NewTableRow.cells;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜