Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/90.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将一个表的内容复制到另一个表中_Javascript_Html_Internet Explorer 8 - Fatal编程技术网

Javascript 将一个表的内容复制到另一个表中

Javascript 将一个表的内容复制到另一个表中,javascript,html,internet-explorer-8,Javascript,Html,Internet Explorer 8,在我当前的应用程序中,我需要将一个表的内容复制到另一个表中。。。通过设置innerHTML,它可以在FF中完美工作。。。但不是在IE8中。。。 以下是我在FF中复制的代码: getID("tableA").innerHTML = getID("tableB").innerHTML; // getID is a custom function i wrote to provide a shorter version of document.getElementById(); TableA为空(仅

在我当前的应用程序中,我需要将一个表的内容复制到另一个表中。。。通过设置innerHTML,它可以在FF中完美工作。。。但不是在IE8中。。。 以下是我在FF中复制的代码:

getID("tableA").innerHTML = getID("tableB").innerHTML;
// getID is a custom function i wrote to provide a shorter version of document.getElementById();
TableA为空(仅存在tbody标记)。表B如下所示:


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

我已经试过使用nodeValue。。或附加数据。。。或外部TML。。但是什么都没用

Internet Explorer不允许您使用innerHTML编辑表的内部-要么全是,要么全是

由于您试图使用innerHTML复制信息,因此完整的副本应该是安全的(即没有任何可能重复的id属性),在这种情况下,我将执行以下操作:

var source = document.getElementById('tableA');
var destination = document.getElementById('tableB');
var copy = source.cloneNode(true);
copy.setAttribute('id', 'tableB');
destination.parentNode.replaceChild(copy, destination);

我有点惊讶地得知,IE 8没有修复这个问题。天啊,说你拖拖拉拉的。这是Internet Explorer实现innerHTML时故意忽略的—您不能在表中设置innerHTML。该功能的创建者已提供。基本上,您可以获得一个实际的tbody节点,并使用replaceChild()将原始表的tbody转换为该节点。

Nice Share。有人能评论一下这是否是一种在FF/Safari/Chrome等应用中有效的方法吗?是的,这是bog标准DOM 1。