首页 > 解决方案 > 在复选框更改数据表中文本框的值

问题描述

我正在使用数据表。我正在对同一列中的所有数据求和

这是我的代码

                {
                    title: "New Price", data: "price",
                    "render": function (data, type, row) {


                        return ' <input type="checkbox" value="' + data + '" >
 <input type="number" id="newCost"  class ="price-input"  value="' + data + '" style="background-color:lightgoldenrodyellow;">';

                    }

        function doSum5() {
           
            var nodes = table7.column(3).nodes();
            // get the value from each input field in each cell:
            var total = table7.column(3).nodes()
                // and then sum up the integer values:
                .reduce(function (sum, node) {
                    return sum + parseFloat($(node).find('input').val());
                }, 0);
            // place the sum in the relevant footer cell:
            var sum = parseFloat(total).toFixed(2)
            $(table7.column(3).footer()).html(sum);


        }

在此处输入图像描述

代码工作正常,现在我的问题是如何可能只选择那些字段作为选中复选框的总和。请指导我

标签: javascriptjqueryajaxdatatable

解决方案


推荐阅读