我思故我強(qiáng)

          動(dòng)態(tài)給表格增加/刪除一行

          <html>
          <head>
          <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
          <title>動(dòng)態(tài)給表格增加/刪除一行</title>
          </head>
          <script language=javascript>
          allCount=1
          function addline()
          {
          newRow=listtable.insertRow(listtable.rows.length);
          newRow.ln=allCount;
          newRow.id=allCount;
          c1=newRow.insertCell(0);
          c1.bgColor="#FFFFFF";
          c1.innerHTML="<input size=10 name=sClass"+allCount+">";
          c2=newRow.insertCell(1);
          c2.bgColor="#FFFFFF";
          c2.innerHTML="<input size=10 name=sMaterial"+allCount+">";
          c3=newRow.insertCell(2);
          c3.bgColor="#FFFFFF";
          c3.innerHTML="<input size=10 name=sSpec"+allCount+">";
          c4=newRow.insertCell(3);
          c4.bgColor="#FFFFFF";
          c4.innerHTML="<input size=10 name=sPrice"+allCount+">";
          c5=newRow.insertCell(4);
          c5.bgColor="#FFFFFF";
          c5.innerHTML="<input size=10 name=sAmount"+allCount+">";
          c6=newRow.insertCell(5);
          c6.bgColor="#FFFFFF";
          c6.innerHTML="<input size=10 name=sFactory"+allCount+">";
          c7=newRow.insertCell(6);
          c7.bgColor="#FFFFFF";
          c7.innerHTML="<input size=10 name=sDeliveryPlace"+allCount+">";
          c8=newRow.insertCell(7);
          c8.bgColor="#FFFFFF";
          c8.innerHTML="<input size=10 name=sNotes"+allCount+">";
          c9=newRow.insertCell(8);
          c9.bgColor="#FFFFFF";
          c9.align="CENTER";
          c9.innerHTML="<input type=checkbox value=t checked name=cPub"+allCount+">";
          c10=newRow.insertCell(9);
          c10.bgColor="#FFFFFF";
          c10.align="CENTER";
          c10.id="line"+allCount;
          c10.innerHTML="<input type=button value=刪除 onclick=delline(line"+allCount+")>";
          c11=newRow.insertCell(10);
          c11.bgColor="#FFFFFF";
          c11.align="CENTER";
          c11.innerHTML="<input type=button value=插入 onclick=insertline(line"+allCount+")>";
          allCount++
          }
          function insertline(lineid)
          {
          for(i=0;i<listtable.rows.length;i++)
          {
          if(listtable.rows[i].cells[9].id==lineid.id)
          {
          newRow=listtable.insertRow(i);
          newRow.ln=allCount;
          newRow.id=allCount;
          c1=newRow.insertCell(0);
          c1.bgColor="#FFFFFF";
          c1.innerHTML="<input size=10 name=sClass"+allCount+">";
          c2=newRow.insertCell(1);
          c2.bgColor="#FFFFFF";
          c2.innerHTML="<input size=10 name=sMaterial"+allCount+">";
          c3=newRow.insertCell(2);
          c3.bgColor="#FFFFFF";
          c3.innerHTML="<input size=10 name=sSpec"+allCount+">";
          c4=newRow.insertCell(3);
          c4.bgColor="#FFFFFF";
          c4.innerHTML="<input size=10 name=sPrice"+allCount+">";
          c5=newRow.insertCell(4);
          c5.bgColor="#FFFFFF";
          c5.innerHTML="<input size=10 name=sAmount"+allCount+">";
          c6=newRow.insertCell(5);
          c6.bgColor="#FFFFFF";
          c6.innerHTML="<input size=10 name=sFactory"+allCount+">";
          c7=newRow.insertCell(6);
          c7.bgColor="#FFFFFF";
          c7.innerHTML="<input size=10 name=sDeliveryPlace"+allCount+">";
          c8=newRow.insertCell(7);
          c8.bgColor="#FFFFFF";
          c8.innerHTML="<input size=10 name=sNotes"+allCount+">";
          c9=newRow.insertCell(8);
          c9.bgColor="#FFFFFF";
          c9.align="CENTER";
          c9.innerHTML="<input type=checkbox value=t checked name=cPub"+allCount+">";
          c10=newRow.insertCell(9);
          c10.bgColor="#FFFFFF";
          c10.align="CENTER";
          c10.id="line"+allCount;
          c10.innerHTML="<input type=button value=刪除 onclick=delline(line"+allCount+")>";
          c11=newRow.insertCell(10);
          c11.bgColor="#FFFFFF";
          c11.align="CENTER";
          c11.innerHTML="<input type=button value=插入 onclick=insertline(line"+allCount+")>";
          allCount++
          return;
          }
          }
          }
          function delline(lineid)
          {
          for(i=0;i<listtable.rows.length;i++)
          {
          for(j=0;j<listtable.rows[i].cells.length;j++)
          {
          if(listtable.rows[i].cells[j].id==lineid.id)
          {
          listtable.deleteRow(i);
          return;
          }
          }
          }
          }
          </script>

          <body>
          <table width=700 height="20" border="0" align="center" cellpadding=0 cellspacing=0 id=listtable>
          <tr align=center height=20>
          <td bgcolor=#FFFFFF><b>品名</b></td>
          <td bgcolor=#FFFFFF><b>材質(zhì)</b></td>
          <td bgcolor=#FFFFFF><b>規(guī)格</b></td>
          <td bgcolor=#FFFFFF><b>價(jià)格</b></td>
          <td bgcolor=#FFFFFF><b>數(shù)量</b></td>
          <td bgcolor=#FFFFFF><b>產(chǎn)地</b></td>
          <td bgcolor=#FFFFFF><b>交貨地</b></td>
          <td bgcolor=#FFFFFF><b>備注</b></td>
          <td bgcolor=#FFFFFF><b>發(fā)布</b></td>
          <td bgcolor=#FFFFFF><b>-</b></td>
          <td bgcolor=#FFFFFF><b>-</b></td>
          </tr>
          </table>
          <table width="700" height="25" border="0" align="center" cellpadding="0" cellspacing="0">
          <tr><td align="center"><input type=button value=增加一行 onclick=addline()></td>
          </tr>
          </table>
          </body>
          </html>

          posted on 2008-08-11 09:50 李云澤 閱讀(658) 評(píng)論(0)  編輯  收藏 所屬分類(lèi): javascriptHTML

          主站蜘蛛池模板: 兖州市| 榕江县| 安远县| 太和县| 沙雅县| 临夏市| 池州市| 平凉市| 镇康县| 呼玛县| 临桂县| 洪泽县| 东安县| 双流县| 隆德县| 焉耆| 根河市| 东丰县| 阳信县| 响水县| 托克托县| 陈巴尔虎旗| 广安市| 广东省| 威远县| 张家港市| 白山市| 岑巩县| 清徐县| 合水县| 凉城县| 夏津县| 阿勒泰市| 垣曲县| 都安| 新宾| 定远县| 天台县| 浠水县| 卫辉市| 名山县|