IE6-IE9不支持table.innerHTML的解决方法分享


  本文标签:table,innerHTML

测试代码:
复制代码 代码如下:

<table id="test">
</table>
<script>
var oTable=document.getElementById("test");
oTable.innerHTML="<tr><td>innerHTML</td></tr>";
</script>


上述代码在IE6-9中无效,直接报错:
  IE9:Invalid target element for this operation.
  IE6-8:Unknown runtime error
  查找IE的文档(http://msdn.microsoft.com/en-us/library/ms533897(VS.85).aspx)后发现有这么一段:

The innerHTML property is read-only on the col, colGroup, frameSet, html, head, style, table, tBody, tFoot, tHead, title, and tr objects.