<html>
<head>
<title>Table test</title>
</head>
<body>
<div id="tableTest">
</div>
</body>
</html>
<script language="JavaScript" type="text/javascript">
<!--
//獲取容器div的引用
var container=document.getElementById("tableTest");
//創建表格對象
var _table=document.createElement("table");
//設置表格屬性
_table.setAttribute("border","1");
_table.setAttribute("borderColor","black");
_table.setAttribute("width","200");
//創建5行
for(var i=0;i<5;i++){
var _tr=_table.insertRow(i);
//創建4列
for(var j=0;j<4;j++){
var _td=_tr.insertCell(j);
var _tn=document.createTextNode(i.toString()+j.toString());
_td.appendChild(_tn);
}
}
//將表格顯示于頁面
container.appendChild(_table);
//-->
</script>
posted on 2008-07-27 13:33
長春語林科技 閱讀(897)
評論(0) 編輯 收藏 所屬分類:
js