动态添加删除表格

<html>
<head>
<meta   http-equiv= "Content-Type "   content= "text/html;   charset=gb2312 ">
<meta   name= "GENERATOR "   content= "Microsoft   FrontPage   4.0 ">
<meta   name= "ProgId "   content= "FrontPage.Editor.Document ">
<title> try </title>
</head>
<body>
<script>
allTrafficCount=1
allCount=1
function   addTrafficeRow()   //增加一行
{
        newRow=trafficeList.insertRow(trafficeList.rows.length);
        newRow.id= "tradt ";
        newRow.ln=allTrafficCount;
       
        c1=newRow.insertCell(0);
        c1.id= "tradtRow ";
        c1.ln=allCount;
        c1.innerHTML= " <input   type=text   name= 'traffic '   size=40   maxlength=200> &nbsp;&nbsp; <input   type=button   value= '删除 '   ln= "   +   allTrafficCount   +   "   onclick= 'javascript:delTrafficeRow(); '> "

        allTrafficCount++;   //总计多少行
        frm.trafficCount.value   =   allTrafficCount;

}

function   delTrafficeRow()   //删除一行
{
        line   =   parseInt(event.srcElement.ln,10);

        if   (line> 0)
                for   (i=1;i <trafficeList.rows.length;i++)

      if   (trafficeList.rows[i].ln==line)   //
                        {
                                trafficeList.deleteRow(i);
              allTrafficCount--;
              frm.trafficCount.value   =     allTrafficCount;
                        }
}
</script>
<form   name=frm>
<table   border= "1 "   id=trafficeList>
<tr> <td   width=100> test </td> </tr>
</table>
<input   type=button   value=add     onclick= "addTrafficeRow() "> <input   name=trafficCount>
</form>
</body>
</html>

你可能感兴趣的:(动态添加删除表格)