Internet Explorer Javascript/ Dom Object add rows problem

穿精又带淫゛_ 提交于 2019-12-07 15:13:34

For your own sanity, use a library like jQuery to achieve this kind of things.

Please, do not use the appendChild method to add rows to a table, or cells to a table row. So you will avoid the need of explicitly creating a TBODY element, appending it to the table, then creating and appending TR elements to that TBODY.

There are standard DOM methods that are specifically intended for this use. Namely:

1.) var newRow = myTable.insertRow(index)
Inserts and returns a new empty row (TR element) at the given index.

2.) myTable.deleteRow(index)
Deletes the row at the given index.

3.) var newCell = myRow.insertCell(index)
Inserts and returns a new empty cell (TD element) at the given index.

4.) myRow.deleteCell(index)
Deletes the cell at the given index.

All those methods normally throw an error if the index argument is out of range. However in some browsers like IE8 the index is optional and if it is omitted the cell or row will be inserted or removed at the end of its parent.

Your code isn't very clear but I think you will append the tr elements to table. But you can't append a tr directly to a table in ie. You need to create a tbody element first add this to table and append then your tr to the tbody element.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!