码迷,mamicode.com
首页 > Web开发 > 详细

发现是在IE6-IE9下,下列元素table,thead,tfoot,tbody,tr,col,colgroup,html,title,style,frameset的innerHTML属性是只读的

时间:2017-08-10 21:07:52      阅读:379      评论:0      收藏:0      [点我收藏+]

标签:creat   标签   var   字符串   table   inner   ace   只读   html   

 table ID="zhutiTable"
html2="<tr></tr>"; 的数据
setTableInnerHTML(document.getElementById(‘zhutiTable‘), html2);
 
function setTableInnerHTML(table, html) {//table 为table对象,html为生成的html字符串
  if (navigator && navigator.userAgent.match(/msie/i)) {
    var temp = table.ownerDocument.createElement(‘div‘);
    temp.innerHTML = ‘<table>‘ + html + ‘</table>‘;//注意此处传进来的html变量包含“<tbody></tbody>”标签  如果HTML变量中没有 则为 ‘<table><tbody>‘ + html + ‘</tbody></table>‘
    table.replaceChild(temp.firstChild.firstChild, table.tBodies[0]);//用生成的div中table的tbody替换原table中的tbody
              // table.appendChild(temp.firstChild.firstChild);   //用于添加 tr 到 到已生成好的table 中
  } else {
    table.innerHTML = html;
  }
}
 
 获取 table  中 的tbody   赋值

// var oTBODYData = document.getElementById(‘zhutiTable‘).tBodies.item(0);
// oTBODYData.innerHTML+=html2;

发现是在IE6-IE9下,下列元素table,thead,tfoot,tbody,tr,col,colgroup,html,title,style,frameset的innerHTML属性是只读的

标签:creat   标签   var   字符串   table   inner   ace   只读   html   

原文地址:http://www.cnblogs.com/yangpeng-jingjing/p/7341013.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!