天天看點

DOM建立表格

近日,在研究DOM建立表格,但是發現有個東西在IE下始終運作不了,細細思量,原來是這個原因

window.οnlοad=function(){
	var table=document.createElement("table");
	table.width=500;
	table.border=1;
	
	table.createCaption().innerHTML="人員表";
	
	var thead=table.createTHead();
	var tr=thead.insertRow(0);
	tr.insertCell(0).innerHTML="姓名";
	tr.insertCell(1).innerHTML="年齡";
	tr.insertCell(2).innerHTML="性别";
	
	//FF、chrome  var tbody=table.createTBody();
	/* IE :*/     var tbody=document.createElement("tbody");
	table.appendChild(tbody);
	var tr=tbody.insertRow(0);
	tr.insertCell(0).innerHTML="李明";
	tr.insertCell(1).innerHTML="25";
	tr.insertCell(2).innerHTML="男";		
	
	var tfoot=table.createTFoot();
	var tr=tfoot.insertRow(0);
	tr.insertCell(0).innerHTML="總數1";
	tr.insertCell(1).innerHTML="總數2";
	tr.insertCell(2).innerHTML="總數3";
	document.body.appendChild(table);
}
           

注意上述代碼中tbody的聲明方式,火狐谷歌下,在table對象下createTBody即可,但是IE不支援這個用法,隻能在document下面createElement。

萬惡的IE!!!!!!!!!!!!!!!

繼續閱讀