1

ユーザーがテーブルの最後の行に入力を入力すると、新しい行を追加したいフォーム内にテーブルがあります。

$('table.form-table').on('input', function() {
    var tableID = '#' + $(this).closest('table').attr('id');
    if(jQuery(this).closest('tr').is(':last-child')) {
        var currTR = $(this).closest('tr');
        var currTRhtml = '<tr>' + currTR.html() + '</tr>';
        var nextRow = jQuery(currTRhtml);

        var checkBox = jQuery('<td class="border-right checks"><input type="checkbox" name="del_000" value="000"></td>');
        jQuery(tableID).append(nextRow);
        checkBox.appendTo(currTR);
    }   
}); 

必要に応じて html コード (簡略化/トリミング):

<table class="form-table"  id="XXX" border="1" cellspacing="0" cellpadding="3">
<thead>
    <tr class="main"><th nowrap colspan="3" align="left" 
        class="border-left border-top border-right">
        <h3>XXX</h3></th>
    </tr>
    <tr>
        <th>header</th>
        </tr>
</thead>
<tbody>
            <tr>
    <input type="hidden" name="isnew" value="">
    <td >
            <input type="text" 
             name="new_text"
             value="">
            </td>
            </tr>
</tbody>
</table>

問題は、これが一度しか機能せず、新しい行を追加し続けないことです。フィルタリングがリセットされlast-childないようです...何か考えはありますか?

4

2 に答える 2