获取动态表值

时间:2017-01-08 17:18:59

标签: javascript jquery

在下面的代码中,我有一个动态表,我将添加多行并在点击提交按钮时输入值我想要所有的表行值。请帮助我这样做。下面提供的代码请参考。

$(document).ready(function () {
         var i = 1;
         $("#add_row").click(function () {
             $('#addr' + i).html("<td>" + (i + 1) + "</td><td><input name='name" + i + "' type='text' placeholder='Name' class='form-control input-md'  /> </td><td><input  name='mail" + i + "' type='text' placeholder='Mail'  class='form-control input-md'></td><td><input  name='mobile" + i + "' type='text' placeholder='Mobile'  class='form-control input-md'></td>");

             $('#tab_logic').append('<tr id="addr' + (i + 1) + '"></tr>');
             i++;

             Test();
         });
         $("#delete_row").click(function () {
             if (i > 1) {
                 $("#addr" + (i - 1)).html('');
                 i--;
             }
         });

     });

       <div class="row clearfix">
        <div class="col-xs-4 column">
            <table class="table table-bordered table-hover" id="tab_logic">
                <thead>
                    <tr >
                        <th class="text-center">
                            #
                        </th>
                        <th class="text-center">
                            Start Range
                        </th>
                        <th class="text-center">
                            End Range
                        </th>
                        <th class="text-center">
                            Value
                        </th>
                    </tr>
                </thead>
                <tbody>
                    <tr id='addr0'>
                        <td>
                        1
                        </td>
                        <td>
                        <input type="text" name='name0'  placeholder='Start Range' class="form-control"/>
                        </td>
                        <td>
                        <input type="text" name='mail0' placeholder='End Range' class="form-control"/>
                        </td>
                        <td>
                        <input type="text" name='mobile0' placeholder='Value' class="form-control"/>
                        </td>
                    </tr>
                    <tr id='addr1'></tr>
                </tbody>
            </table>
        </div>
    </div>
<input type="button" text="Submit" />

1 个答案:

答案 0 :(得分:1)

要删除行,您无法获取要删除的行。

试试这个