javascript 动态创建表格
<html>
<head>
<script>
functioncreateTable(rows,lines){
this.rows=rows;
this.lines=lines;
varBody=document.getElementById('body');
varTable=document.createElement('table');//创建table标签元素
Table.setAttribute('border','1');
//给table标签添加其他属性
for(vari=0;i<this.rows;i++){
varlRow=document.createElement('tr');
for(varj=0;j<this.lines;j++){
vartextNode=document.createTextNode(i+','+j);
varlLine=document.createElement('td');
lLine.appendChild(textNode);
lRow.appendChild(lLine);
}
Table.appendChild(lRow);
}
Body.appendChild(Table);
}
</script>
</head>
<body>
<divid="body"></div>
</body>
<scripttype="text/javascript">
createTable(10,10);
</script>
</html>
第二种方法:
<script>
functioncreateTable(rows,lines){
this.rows=rows;
this.lines=lines;
varBody=document.getElementById('body');
varTable=document.createElement('table');
Table.setAttribute('border',1);
for(vari=0;i<this.rows;i++){
varrow=Table.insertRow(i);
for(varj=0;j<this.lines;j++){
varcells=row.insertCell(j);
cells.innerHTML=i+','+j
}
}
Body.appendChild(Table);
}
</script>
热门推荐
10 八一幼儿祝福语大全简短
11 公司乔迁食堂祝福语简短
12 婚礼结束聚餐祝福语简短
13 儿媳买车妈妈祝福语简短
14 毕业送礼老师祝福语简短
15 同事辞职正常祝福语简短
16 恭贺新婚文案祝福语简短
17 金店立秋祝福语简短英文
18 婆婆高寿祝福语大全简短