javascript向表中添加行--浏览器兼容性问题

ie6,ie7对table.appendChild("tr")的支持和IE8不一样,用insertRow、insertCell来代替或者为表格添加tbody,然后向tbody中添加tr。FF不支持InnerText。

所以动态加载网站列表的程序修改为:

var tr = tableLinks.insertRow(-1);//FF必须加-1这个参数

var td1 = tr.insertCell(-1);

td1.innerText = key;

var td2 = tr.insertCell(-1);

td2.innerHTML = "<a href='" + value + "'>" + value + "</a>";

或者:<table >

<tbody></tbody>

</table>,然后tableLinks. tBodies[0].appendChild(tr);