Copy the content of one table into another

前端 未结 2 900
伪装坚强ぢ
伪装坚强ぢ 2021-01-14 08:18

In my current application i need to copy the content of one table into another... With setting innerHTML it works perfectly in FF... but not in IE8... Here is the Code i us

相关标签:
2条回答
  • 2021-01-14 08:55

    Internet Explorer doesn't let you edit the inside of tables with innerHTML - it is all or nothing.

    Since you are trying to use innerHTML to copy the information, a complete copy should be safe (i.e. not have any id attributes that might become duplicated), in which case I would do this:

    var source = document.getElementById('tableA');
    var destination = document.getElementById('tableB');
    var copy = source.cloneNode(true);
    copy.setAttribute('id', 'tableB');
    destination.parentNode.replaceChild(copy, destination);
    
    0 讨论(0)
  • 2021-01-14 09:08

    I'm kind of surprised to learn this didn't get fixed for IE 8. Geez, talk about dragging your feet. This is an intentional omission in Internet Explorer's implementation of innerHTML — you can't set innerHTML in a table. The creator of the feature has offered an explanation and a workaround. Basically, you can get hold of an actual tbody node and use replaceChild() to turn the original table's tbody into that.

    0 讨论(0)
提交回复
热议问题