1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > javascript 动态创建表格

javascript 动态创建表格

时间:2020-09-11 14:17:37

相关推荐

javascript  动态创建表格

<html><head><script>function createTable(rows,lines){this.rows=rows;this.lines=lines;var Body=document.getElementById('body');var Table=document.createElement('table');//创建table标签元素Table.setAttribute('border','1');//给table标签添加其他属性for(var i=0;i<this.rows;i++){var lRow=document.createElement('tr');for(var j=0;j<this.lines;j++){var textNode=document.createTextNode(i+','+j);var lLine=document.createElement('td');lLine.appendChild(textNode);lRow.appendChild(lLine);}Table.appendChild(lRow);}Body.appendChild(Table);}</script></head><body ><div id="body"></div></body><script type="text/javascript">createTable(10,10);</script></html>

View Code

第二种方法:

<script>function createTable(rows,lines){this.rows=rows;this.lines=lines;var Body=document.getElementById('body');var Table=document.createElement('table');Table.setAttribute('border',1);for(var i=0;i<this.rows;i++){var row=Table.insertRow(i);for(var j=0;j<this.lines;j++){var cells=row.insertCell(j);cells.innerHTML=i+','+j}}Body.appendChild(Table);}</script>

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。