</div>
<script type="text/javascript">
//创建表格
function createTable(id,rows,cells,tbid){
var tb=document.createElement("table")
var tbody = document.createElement("tbody")
for(var i=0i<rowsi++){
var tr=document.createElement("tr")
for(var j=0j<cellsj++){
var cell=document.createElement("td")
tr.appendChild(cell)
}
tbody.appendChild(tr)
}
tb.appendChild(tbody)
tb.setAttribute("id",tbid)//设置创建的TABLE的ID
document.getElementById(id).appendChild(tb)
}
for(i=0i<4i++){
tdid="aaa_"+i.toString()//表格id
createTable("aaa",2,2,tdid)//创建2行2列的表格
document.getElementById(tdid).setAttribute('border',1)//显示表格表框
}
</script>
<html><head>
<style type="text/css">
body
{
text-align:center
}
table
{
font-size:12px
text-align:center
border:1px solid #EFEFEF
border-cellspan:cellspan
margin-top:50px
}
td
{
border:1px solid #EFEFEF
}
</style>
<script type="text/javascript">
function changbackgroundcolor()
{
var trs=document.getElementById("table1").getElementsByTagName("tr")
for(var i=0i<trs.lengthi++)
{
if(i%2==0)
{
trs[i].style.backgroundColor="#FFFFFF"
}
else
{
trs[i].style.backgroundColor="#000000"
}
}
}
</script>
</head>
<body onLoad="changbackgroundcolor()">
<table width="700" id="table1" cellspacing="0" cellpadding="5" align="center" >
<tr>
<td>1</td>
<td>1</td>
<td>1</td>
<td>1</td>
</tr>
<tr>
<td>2</td>
<td>2</td>
<td>2</td>
<td>2</td>
</tr>
<tr>
<td>3</td>
<td>3</td>
<td>3</td>
<td>3</td>
</tr>
<tr>
<td>4</td>
<td>4</td>
<td>4</td>
<td>4</td>
</tr>
<tr>
<td>5</td>
<td>5</td>
<td>5</td>
<td>5</td>
</tr>
<tr>
<td>6</td>
<td>6</td>
<td>6</td>
<td>6</td>
</tr>
</table>
</body>
</html>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)