javascript自动生成表格行

//给指定的表格增加一行  
    function addRow(TableName)
       {
       var table=document.getElementById(TableName);
       //添加一行
       var tr_node = document.createElement("tr");
       //设置列数组
       var td_node =new Array(11);
       var td_node_id =new Array("td_1","td_2","td_3","td_4","td_5","td_6","td_7","td_8","td_9","td_10","td_11");
       var td_node_width =new Array("5%","10%","10%","10%","20%","20%","5%","5%","5%","5%","5%");

       input_node_type =”Input”
       //添加列
       for(i=0;i<11;i++)
       {
           td_node[i] = document.createElement("td");
           td_node[i].setAttribute("id",td_node_id[i]);
           td_node[i].setAttribute("width",td_node_width[i]);
       }
       //添加列的内容和内容的属性,此处是新建一个Input框,并放入单元格中。
       for(i=0;i<11;i++)
       {
           var input_node = document.createElement("input");
           input_node.setAttribute("type",input_node_type);
           input_node.setAttribute("id",td_node_id[i]+”Input”);          
           td_node[i].appendChild(input_node);
           tr_node.appendChild(td_node[i]);
       }

       //将新建的行元素增加到表格中
       table.appendChild(tr_node);
}

posted @ 2009-11-19 15:29  溪水云天  阅读(574)  评论(0编辑  收藏  举报