Home >Web Front-end >JS Tutorial >javascript dynamically create tables_javascript skills

javascript dynamically create tables_javascript skills

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-05-16 16:21:331036browse

Copy code The code is as follows:


                                                                                                                                                                                                                         function createTable(rows,lines){
This.rows=rows;
This.lines=lines;
                  var Body=document.getElementById('body');
                      var Table=document.createElement('table');//Create table tag element
                    Table.setAttribute('border','1');
//Add other attributes to the table tag
for(var i=0;i                             var lRow=document.createElement('tr');
for(var j=0;j                                                             var textNode=document.createTextNode(i ',' j);
                                                                                                 var lLine=document.createElement('td');
lLine.appendChild(textNode);
lRow.appendChild(lLine);
                                                                                                       }                        Table.appendChild(lRow);
                 }
                      Body.appendChild(Table);
                }
                                                                                                                                                                                                                                                                                                                                     

                                                                                                 
Copy code

The code is as follows:


<script><br />                 function createTable(rows,lines){<br />                     this.rows=rows;<br />                     this.lines=lines;<br />                     var Body=document.getElementById('body');<br />                     var Table=document.createElement('table');<br />                     Table.setAttribute('border',1);<br />                     for(var i=0;i<this.rows;i ){<br />                         var row=Table.insertRow(i);<br />                         for(var j=0;j<this.lines;j ){<br />                             var cells=row.insertCell(j);<br />                             cells.innerHTML=i ',' j<br />                         }<br />                     }<br />                     Body.appendChild(Table);<br />                     <br />                 }<br />             </script>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn