如何使用jQuery在html表中动态添加新行

在这里输入图像描述

在我的html表格中,我有几个输入元素。我希望在表格末尾插入一行新的输入元素,当用户在填写上一个年龄段之后点击输入按钮时。 我希望图片会让事情更清楚..是否有可能使用jquery,因为我是jquery的新手。 任何形式的帮助将不胜感激。


有一些猜测你的表格html结构,总的想法是这样的:

$('input.last').keyup(function handleEnter(e){
    //enter hit on the input that has class last
    if(e.which == 13) {

       $(this).removeClass('last').unbind('keyup');

       $('.myTable').append('<tr><td><input name="input1"/></td><td><input name="input1"/> </td><td><input name="input1" class="last"/></td></tr>');

       $('.last').keyup(handleEnter);
    }
});

尝试http://datatables.net/

请参阅以下基本添加:

http://datatables.net/release-datatables/examples/api/add_row.html

和这个:

http://code.google.com/p/jquery-datatables-editable/wiki/AddingNewRecords

http://jquery-datatables-editable.googlecode.com/svn/trunk/addingrecords.html


在jquery中使用最后一行的最后一列作为选择器。 启动它的onclick事件并在表格末尾添加一个新的tr

代码在这里

 <script>
            $(document).ready(function () {

                $('#tableId tr:last td:last').click(function () {
                    var tr = $('this').closest('tr');
                    $('#tableId').append(tr);
                });
            });
        </script>
链接地址: http://www.djcxy.com/p/22989.html

上一篇: How to add new row dynamically in html table using jquery

下一篇: Table with twitter bootstrap and jQuery