首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

js动态生成报表

2012-06-29 
js动态生成表格直接上代码:html head title /title scripttype text/javascriptfunction Tes

js动态生成表格
直接上代码:

<html> <head> <title> </title> <script   type= "text/javascript">     function TestSecond()     {         var divt=document.getElementById("div1"); //显示DIV        var tablet=document.createElement("table"); //创建表        tablet.border=1;        var textRow=2;//行数        var textCell=3;//列数        var num = 0;        for(var i=0;i<textRow;i++)         {              var row=tablet.insertRow(num);             for(var j=0;j<textCell;j++)             {                 var cell=row.insertCell(num);                 cell.innerHTML="hello";                 cell.width=150;                 cell.height = 20;             }         }         num = num + 1;                   divt.appendChild(tablet);      } //根据tr的ID删除一行(未被调用,备用)function deleteOneTr(trId){var theTab = document.getElementById("oneTab")//根据表格ID得表格var row=document.getElementById(trId); var index=row.rowIndex;theTab.deleteRow(index);}</script> </head> <body> <form id="Form1" method="post" runat="server"> <table align="center">                              <tr>                     <td align="center" colspan="2"><input type="button" value="生成表格" onClick="javascript:TestSecond();"/></td>                 </tr>             </table> <div id="div1" style="position:absolute;"></div>      </form> </body> </html> 

热点排行