日期:2014-05-16  浏览次数:20483 次

这是javascript自由添加行,删行! 如何在指定的位置插入新的一行
<!--自由添加行-->
   
<table   id= "t1 "   border= "0 "   cellpadding= "0 "   cellspacing= "0 "   width= "95% "   >  
  <tr>
    <td   width= "80 "> <center>
        <input   type= "radio "     name= "tt "> </center> </td>
    <td   width= "125 "> <center> <input   name= "model "   class= "selBoxText "   id= "model "   value= " "   size= "15 "   onFocus= "watermarkEnter(this, ' ');eventRelation(this, 'UpLoadFile1_ShowTags '); "   > </center> </td>
    <td   width= "107 "> <center> <input   name= "xinghao "   type= "text "   id= "xinghao "   size= "12 "> </center> </td>
    <td   width= "123 "> <center>
        <input   name= "Pack "   type= "text "   id= "Pack "   size= "12 "   onKeyPress= "if   (event.keyCode!=46   &&   event.keyCode!=45   &&   (event.keyCode <48   ||   event.keyCode> 57))   event.returnValue=false ">
    </center> </td>
    <td   width= "123 "> <center>
        <input   name= "Costprice "   type= "text "   id= "Costprice "   size= "12 "   onKeyPress= "if   (event.keyCode!=46   &&   event.keyCode!=45   &&   (event.keyCode <48   ||   event.keyCode> 57))   event.returnValue=false ">
    </center> </td>
    <td   width= "130 "   align= "center "> <input   name= "bak "   type= "text "   id= "bak "   size= "15 "> </td>
    <td> &nbsp; </td>
  </tr>
</table>

            <!--自由添加行-->

      <input   type= "button "   onClick= "add() "   value= "添加一行 ">
            &nbsp;   &nbsp;
                <input   type= "button "   onClick= "del() "   value= "删除一行 ">  


<script   language= "javascript ">

//添加一行和删除一行
function   add(){
var   tr   =t1.insertRow();
tr.insertCell(0).innerHTML   =   ' <center> <input   type= "radio "     name= "tt "> </center> ';
tr.insertCell(1).innerHTML   =   ' <center> <input   name= "model "   class= "selBoxText "   id= "model "   value= " "   size= "15 "> </center> ';
tr.insertCell(2).innerHTML   =   ' <center> <input   name= "xinghao "   type= "text "   id= "xinghao "   size= "12