2010-12-23 98 views
0

我試圖在常規HTML表格上插入行。將行插入到具有文本輸入的表格中

每一行具有<input type="text">元件。

但每次我通過JavaScript添加新行時間,數據或值包含在現有<inputs>消失。

下面的代碼:

<table id="tableSeriales" summary="Seriales" class="servicesT" cellspacing="0" style="width: 100%"> 
    <tr> 
     <td class="servHd">Seriales</td> 
    </tr> 
    <tr> 
    <td class="servBodL"> 
      <input id="0" type="text" value="" style="color: blue; width: 100%"/> 
     </td> 
    </tr> 
</table> 
<a href="javascript:addRow()">Add row</a> 

而且,JavaScript的樣子:

function addRow() { 
     var rowCount = $('#tableSeriales tr').length; 
     $("#tableSeriales").html(
       $("#tableSeriales").html() + 
       '<tr><td class="servBodL"><input id="' + (rowCount +1) + '"type="text" value="" style="color: blue; width: 100%" onkeypress="return handleKeyPress(event,this.form)"/></td></tr>' 
      ); 
    } 

回答

0

使用$('html code goes here').appendTo('#tableSeriales');

$('#tableSeriales').append('html code goes here');

相關問題