将一个表的内容复制到另一个表中 [英] Copy the content of one table into another

查看:95
本文介绍了将一个表的内容复制到另一个表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我目前的应用程序中,我需要将一个表的内容复制到另一个表中......通过设置innerHTML,它在FF中完美运行...但不是在IE8中...
这是我以前使用的代码在FF中复制:

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 used to copy in FF:

getID("tableA").innerHTML = getID("tableB").innerHTML;
// getID is a custom function i wrote to provide a shorter version of document.getElementById();

TableA为空(仅存在tbody标签)。 TableB看起来像这样:

TableA is empty (only the tbody tag exists). TableB is looking like this:



table
  tbody
    tr
      td "Content" /td
      td "Content" /td
    /tr
  /tbody
/table

我已经尝试过使用nodeValue ..或者appendData ...或outerHTML ..但是没有真正有效...

I already tried using nodeValue.. or appendData... or outerHTML.. but nothing really worked...

推荐答案

Internet Explorer不允许您使用innerHTML编辑表格内部 - 它是全部或全部。

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

由于您正在尝试使用innerHTML来复制信息,因此完整的副本应该是安全的(即没有任何可能重复的id属性),在这种情况下我会这样做:

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);

这篇关于将一个表的内容复制到另一个表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆