今天早上回到公司,发现写程序在谷歌浏览器显示正常,在IE下显示错误,查其原因,发现IE6到IE9不支持,table.innerHTML方法,于是在网上搜到一个方法,来解决这个问题
/**
* IE6-IE9不支持table.innerHTML
* @param table
* @param html
* @return
*/
function setTableInnerHTML(table, html) {
if(navigator && navigator.userAgent.match(/msie/i)){
var temp = table.ownerDocument.createElement('div');
temp.innerHTML = '<table><tbody>' + html + '</tbody></table>';
if(table.tBodies.length == 0){
var tbody=document.createElement("tbody");
table.appendChild(tbody);
}
table.replaceChild(temp.firstChild.firstChild, table.tBodies[0]);
} else {
table.innerHTML=html;
}
}