javascript Miltiple таблицы и массивы - PullRequest
0 голосов
/ 26 апреля 2020

Я хочу написать код для общего количества данных моих таблиц, когда пользователь вводит данные, и у меня есть несколько таблиц с разными идентификаторами и с одинаковыми классами. Я хочу сделать общее количество входов на клавиатуре или когда пользователь вводит данные. если кто-нибудь знает другой метод, кроме этого, пожалуйста, помогите мне

                <thead>
                <th>Computed Amount</th>
                </thead>
                <tbody>
<td><input type="text" style="text-align:right;" name="task_compute[]"  class="form-control calculate" autocomplete="off" class="form-group"  /></td>
<td><input type="text" style="text-align:right;" name="task_compute1[]"  class="form-control calculate" autocomplete="off" class="form-group"  /></td>
<td><input type="text" style="text-align:right;" name="task_compute2[]"  class="form-control calculate" autocomplete="off" class="form-group"  /></td>
      </tbody>
                <tfoot>
    <td style="padding-top:15px;" align="right"><b>TOTAL SALARY</b>
                </td><td>
                        <input type="text" style="text-align:right;" name="sub_total[]" id="sub_total" value="" class="form-control"  class="form-group sub_total"  ></td></tfoot>
</table>

 <table id="example123" class="table example122 table-bordered">
                <thead>
                <th>Computed Amount</th>
                </thead>
                <tbody>
<td><input type="text" style="text-align:right;" name="task_compute[]"  class="form-control calculate" autocomplete="off" class="form-group"  /></td>
<td><input type="text" style="text-align:right;" name="task_compute1[]"  class="form-control calculate" autocomplete="off" class="form-group"  /></td>
<td><input type="text" style="text-align:right;" name="task_compute2[]"  class="form-control calculate" autocomplete="off" class="form-group"  /></td>
      </tbody>
                <tfoot>
    <td style="padding-top:15px;" align="right"><b>TOTAL SALARY</b>
                </td><td>
                        <input type="text" style="text-align:right;" name="sub_total[]" id="sub_total" value="" class="form-control"  class="form-group sub_total"  ></td></tfoot>
</table>```





//Js& Jquery

 ```$('.example122 > tbody > .calculate > input[type=text]:nth-child(1) ').on('input', '.calculate', function () {
        var id=$(this).parents('table').attr('id');
        calculateTotal(id);


});


    function calculateTotal(id) 
    {
        var grandTotal = 0;

                             $('#'+id+' > tbody > tr').each(function() {
            var c_sbt = $('.calculate', this).val();
                          grandTotal += parseFloat(c_sbt);
                          });

        var subT = parseFloat(grandTotal);


        $('.sub_total').val(subT.toFixed(2));
    }```




I am trying to run the above js and jquery but it is not working
...