IE6-IE9中tbody的innerHTML不能賦值.
獲取時所有瀏覽器都彈出了tr的字符串,但設置時IE6-9不支持,而且報錯,如圖
解決方案:
1. 可以換個添加屬性,如:appendChild,
tbody.appendChild = "<tr></tr>"
2. 添加判斷
var s = navigator.userAgent.toLowerCase();
var BrowserInfo = {
IsIE: /*@cc_on!@*/false,
IsIE9Under: /*@cc_on!@*/false && (parseInt(s.match(/msie (\d+)/)[1], 10) <= 9),
};
if( BrowserInfo.IsIE9Under ){
tbody.appendChild = "<tr></tr>";
}else{
tbody.innerHTML = "<tr></tr>";
}
3. 包裝整個table
var table = "<table><tbody><tr></tr></tbody></table>"
div.innterHTML = table;
將最外層table也納入到字符串中,使用div.innerHTML