The example in this article describes how to display dynamic table headers and columns using JavaScript. Share it with everyone for your reference. The details are as follows:
<!-- 作者:恺哥 时间:2008-11-5 用途:测试动态表头与动态表列的展现 --> <html> <head> <title>test</title> </head> <body> <script language="javascript"> //初始化表列 var t_column = new Array("col_head"); for(var m=0;m<10;m++){ t_column.push("col"+m); } //初始化表行 var t_row = new Array(); for(var m=0;m<5;m++){ t_row.push("row"+m); } function p(o){ document.writeln(o); } p("<table width=\"95%\" border=\"1\">"); p("<tr>"); for(var i=0;i<t_column.length;i++){ p("<td>"+t_column[i]+"</td>"); } p("</tr>"); for(var j=0;j<t_row.length;j++){ p("<tr>"); p("<td>"+t_row[j]+"</td>"); for(var k=1;k<t_column.length;k++){ p("<td>value"+k+"</td>"); } p("</tr>"); } p("</table>"); </script> </body> </html>
I hope this article will be helpful to everyone’s JavaScript programming design.