代码实现的是按ENTER键插入一行.序号那里不会自动增加,请帮我修改一下.谢谢大家了..另外如果再帮我加上一个按"DEL"键删除的功能就更完美了.谢谢大家了.  <table width='100%' border='1' cellpadding='0' cellspacing='0'>
                      <tr align='center' bgcolor='#E6E6E6'> 
                        <td width='30' height='28' align="center" bgcolor='#E6E6E6'>序号</td>
                        <td width="100" bgcolor='#E6E6E6'>日期</td>
                        <td width="150" bgcolor='#E6E6E6'>A</td>
                        <td width="100" bgcolor='#E6E6E6'>B</td>
                        <td width="100" bgcolor='#E6E6E6'>C</td>
                        <td bgcolor='#E6E6E6'>D</td>
                        <td width="70" bgcolor='#E6E6E6'>E</td>
                        <td width="40" bgcolor='#E6E6E6'>F</td>
                        <td width="80" bgcolor='#E6E6E6'>G</td>
                        <td bgcolor='#E6E6E6'>H</td>
                      </tr>
   <tr id='addtable' align='center' bgcolor='#FFFFFF'>     
                        <td height="28"><input size="3"  type="hidden" >ID</td>
                        <td><input class="inputbian" size="10" type="hidden">2011-3-24</td>
                        <td><input class="inputbian" style="width=140" size="18" onmouseover='this.focus()'></td>
                        <td><input class="inputbian"  style="width=100" size="12" onmouseover='this.focus()'></td>
                        <td><input style="width=100" class="inputbian" size="12" onmouseover='this.focus()'></td>
                        <td><input class="inputbian" style="width=60" size="5" onmouseover='this.focus()'></td>
                        <td><input class="inputbian" style="width=40" size="8" onmouseover='this.focus()'></td>
                        <td><input class="inputbian" style="width=30" size="5" onmouseover='this.focus()'></td>
                        <td><input class="inputbian" style="width=70" size="10" onmouseover='this.focus()'></td>
<td><input class="inputbian" style="width=70" size="10" onmouseover='this.focus()'></td>
                      </tr>
  
        </table>
        </td>
    </tr>
  </table>
</body>
</html>
<script language="JavaScript">var i=1;
//设置行号
function Addrow(){   var newTR = addtable.cloneNode(true);
   newTR.id="a"+(++i);
   addtable.parentNode.insertAdjacentElement("beforeEnd",newTR);
   rows=document.getElementById("rows").rowIndex;
   RowReset();
}function ShortcutKey(){ 
if(window.event.keyCode==13) 
    Addrow()

document.onkeydown=ShortcutKey; 
</script>

解决方案 »

  1.   


    <table width='100%' border='1' cellpadding='0' cellspacing='0'>
      <tr align='center' bgcolor='#E6E6E6'> 
      <td width='30' height='28' align="center" bgcolor='#E6E6E6'>序号</td>
      <td width="100" bgcolor='#E6E6E6'>日期</td>
      <td width="150" bgcolor='#E6E6E6'>A</td>
      <td width="100" bgcolor='#E6E6E6'>B</td>
      <td width="100" bgcolor='#E6E6E6'>C</td>
      <td bgcolor='#E6E6E6'>D</td>
      <td width="70" bgcolor='#E6E6E6'>E</td>
      <td width="40" bgcolor='#E6E6E6'>F</td>
      <td width="80" bgcolor='#E6E6E6'>G</td>
      <td bgcolor='#E6E6E6'>H</td>
      </tr>
    <tr id='addtable' align='center' bgcolor='#FFFFFF'>  
      <td height="28">1</td>
      <td><input class="inputbian" size="10" type="hidden">2011-3-24</td>
      <td><input class="inputbian" style="width=140" size="18" onmouseover='this.focus()'></td>
      <td><input class="inputbian" style="width=100" size="12" onmouseover='this.focus()'></td>
      <td><input style="width=100" class="inputbian" size="12" onmouseover='this.focus()'></td>
      <td><input class="inputbian" style="width=60" size="5" onmouseover='this.focus()'></td>
      <td><input class="inputbian" style="width=40" size="8" onmouseover='this.focus()'></td>
      <td><input class="inputbian" style="width=30" size="5" onmouseover='this.focus()'></td>
      <td><input class="inputbian" style="width=70" size="10" onmouseover='this.focus()'></td>
    <td><input class="inputbian" style="width=70" size="10" onmouseover='this.focus()'></td>
      </tr>
     
      </table>
      </td>
      </tr>
      </table>
    </body>
    </html>
    <script language="JavaScript">var i=1;
    //设置行号
    function Addrow(){  var newTR = addtable.cloneNode(true);
      newTR.id="a"+(++i);
      addtable.parentNode.insertAdjacentElement("beforeEnd",newTR);
      newTR.children[0].innerHTML=i;
    }function ShortcutKey(){ 
    if(window.event.keyCode==13) 
      Addrow()

    document.onkeydown=ShortcutKey; 
    </script>
      

  2.   

    退格键删除最后一行
    <table id="table1" width='100%' border='1' cellpadding='0' cellspacing='0'>
      <tr align='center' bgcolor='#E6E6E6'> 
      <td width='30' height='28' align="center" bgcolor='#E6E6E6'>序号</td>
      <td width="100" bgcolor='#E6E6E6'>日期</td>
      <td width="150" bgcolor='#E6E6E6'>A</td>
      <td width="100" bgcolor='#E6E6E6'>B</td>
      <td width="100" bgcolor='#E6E6E6'>C</td>
      <td bgcolor='#E6E6E6'>D</td>
      <td width="70" bgcolor='#E6E6E6'>E</td>
      <td width="40" bgcolor='#E6E6E6'>F</td>
      <td width="80" bgcolor='#E6E6E6'>G</td>
      <td bgcolor='#E6E6E6'>H</td>
      </tr>
    <tr id='addtable' align='center' bgcolor='#FFFFFF'>  
      <td height="28">1</td>
      <td><input class="inputbian" size="10" type="hidden">2011-3-24</td>
      <td><input class="inputbian" style="width=140" size="18" onmouseover='this.focus()'></td>
      <td><input class="inputbian" style="width=100" size="12" onmouseover='this.focus()'></td>
      <td><input style="width=100" class="inputbian" size="12" onmouseover='this.focus()'></td>
      <td><input class="inputbian" style="width=60" size="5" onmouseover='this.focus()'></td>
      <td><input class="inputbian" style="width=40" size="8" onmouseover='this.focus()'></td>
      <td><input class="inputbian" style="width=30" size="5" onmouseover='this.focus()'></td>
      <td><input class="inputbian" style="width=70" size="10" onmouseover='this.focus()'></td>
    <td><input class="inputbian" style="width=70" size="10" onmouseover='this.focus()'></td>
      </tr>
     
      </table>
      </td>
      </tr>
      </table>
    </body>
    </html>
    <script language="JavaScript">var i=1;
    //设置行号
    function Addrow(){  var newTR = addtable.cloneNode(true);
      newTR.id="a"+(++i);
      addtable.parentNode.insertAdjacentElement("beforeEnd",newTR);
      newTR.children[0].innerHTML=i;
    }
    function Delrow(){
       var num = table1.rows.length;
    if(num==2) return;
    table1.deleteRow(table1.rows[num-1].rowIndex);
    i--;
    }
    function ShortcutKey(){
    if(window.event.keyCode==8) 
      Delrow();
    if(window.event.keyCode==13) 
      Addrow();

    document.onkeydown=ShortcutKey; 
    </script>