Rumah >hujung hadapan web >tutorial js >javascript mencipta kemahiran tables_javascript secara dinamik

javascript mencipta kemahiran tables_javascript secara dinamik

WBOY
WBOYasal
2016-05-16 16:21:33967semak imbas

Salin kod Kod adalah seperti berikut:


                                                                                                                                                                                                                                           fungsi createTable(baris, garisan){
This.rows=rows;
This.lines=lines;
                  var Body=document.getElementById('body');
                      var Table=document.createElement('table');//Buat elemen teg jadual
                    Table.setAttribute('sempadan','1');
//Tambahkan atribut lain pada teg jadual
for(var i=0;i                              var lRow=document.createElement('tr');
for(var j=0;j                                                                     var textNode=document.createTextNode(i ',' j);
... lLine.appendChild(textNode);
lRow.appendChild(lLine);
                                                                                                                                                                            Table.appendChild(lRow);
                 }
                       Body.appendChild(Jadual);
                }