将行插入带有文本输入的表中

时间:2010-12-23 15:09:36

标签: html html-table row editing

我正在尝试在常规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>'
            );
    }

1 个答案:

答案 0 :(得分:0)

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

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

相关问题