Keyup事件不使用jquery生成的字段

alp*_*phy 0 javascript jquery

我用jquery动态生成了一个表数据.最初,当我用php完成它时,keyup事件工作得很好,我能够在T.Amount列中找到表的每一行的.qestimate和#number_of_houses的产品,但现在它不起作用,代码清单

HTML:

                           <table class="tg tg-table-light-1" border="">
                                <thead>
                                    <tr>
                                        <th>No.</th>
                                        <th>Material</th>
                                        <th>Qty</th>                                 
                                        <th>T. Amount</th>    
                                      </tr>
                                </thead>
                             </table>
Run Code Online (Sandbox Code Playgroud)

JQuery的:

  $(document).ready(function() {  

    table=$('.tg-table-light-1');




   $.getJSON("<?php echo base_url() . 'material_estimation/loadEstimates' ?>/", function(materialdetails) {
        i=1;
    $.each(materialdetails , function(i, materials){
    newmaterials= materials.Materials;
    sanitized_newmaterials=newmaterials.replace(/<\/?([a-z][a-z0-9]*)\b[^>]*>?/gi, '');
    data="<tr class=\"tg-even\">

    <td class=\"\">"+i+"</td>\n\
                  <td class=\"tg-even\">"+sanitized_newmaterials+"</td>\n\
                  <td class=\"\"><input type=\"text\"  style=\"width:40px; text-align: center;\" class=\"qestimate\" name=\"qestimate[]\" value=\""+materials.Quantity_estimate+"\"/></td>\n\
                <td class=\"\"><input type=\"text\"  style=\"width:40px; text-align: center;\" class=\"tqty\" name=\"tqty[]\" value=\""+materials.total_quantity+"\"/></td>\n\

                                    </tr>";   
                    table.append(data);

                    i++;
                     });                        
                });
Run Code Online (Sandbox Code Playgroud)

//触发事件

 $(".tg-even input").keyup(multInputs);
Run Code Online (Sandbox Code Playgroud)

//我正在调用的函数但没有工作

 function multInputs() {
                var mult = 0;

                $("tr.tg-even").each(function() {
                    // get the values from this row:
                    var $val1 = $('#number_of_houses option:selected').val();
                    var $val2 = $('.qestimate', this).val();
                    var $total = ($val1 * 1) * ($val2 * 1);
                    var qty = $('.tqty', this).val($total);


                });


        }
Run Code Online (Sandbox Code Playgroud)

})

Alv*_*aro 6

使用授权:

$(document).on('keyup', '.tg-even input', function(e){
     // ...
});
Run Code Online (Sandbox Code Playgroud)

或者如果你愿意:

$(document).on('keyup', '.tg-even input', multInputs);
Run Code Online (Sandbox Code Playgroud)