Javascript 循环表中的多个数组并在单个数组中合并

Javascript 循环表中的多个数组并在单个数组中合并,javascript,jquery,arrays,Javascript,Jquery,Arrays,我的工作项目,有一个表,其中包含多个结果的标题,数字,金钱和复选框。我需要确定复选框是否未选中,并且不会将结果合并到单个数组中。我们如何做到这一点?忠告 我想要组合,例如: 进入单个数组,如: 总和大,1.9995,1;总和小,1.9995,1;虎,1.9995,1; html: <tbody id="confirm-table-body"> <tr> <td> 总和大</td> <td style="color: red

我的工作项目,有一个表,其中包含多个结果的标题,数字,金钱和复选框。我需要确定复选框是否未选中,并且不会将结果合并到单个数组中。我们如何做到这一点?忠告

我想要组合,例如:

进入单个数组,如:

总和大,1.9995,1;总和小,1.9995,1;虎,1.9995,1;
html:

<tbody id="confirm-table-body">
<tr>
    <td> 总和大</td>
    <td style="color: red">1.9995</td>
    <td style="padding: 3px 10px 3px 10px"><input value="1" style="width: 80px"></td>
    <td><input type="checkbox" checked=""></td>
</tr>
<tr>
    <td> 总和小</td>
    <td style="color: red">1.9995</td>
    <td style="padding: 3px 10px 3px 10px"><input value="1" style="width: 80px"></td>
    <td><input type="checkbox" checked=""></td>
</tr>
<tr>
    <td> 虎</td>
    <td style="color: red">1.9995</td>
    <td style="padding: 3px 10px 3px 10px"><input value="1" style="width: 80px"></td>
    <td><input type="checkbox" checked=""></td>
</tr>
<tr>
    <td colspan="2">组数: <span id="confirm-gropup-nums">3</span></td>
    <td colspan="2">总金额: <span id="confirm-total-amount">3</span></td>
</tr>
</tbody>
试试这个

函数getCheckedRows(){ var-arr=[]; $('table:checkbox:checked')。每个(函数(){ td=$(this).closest('tr')。find('td'); arr.push([$(td[0]).text(),$(td[1]).text(),$(td[2]).find('input').val()].join()); }); $(“#确认总额”).text($(“表格:复选框:已选中”).length) 返回arr.join(“;”); } $('table:checkbox')。在('change',function()上{ log(getCheckedRows()); }); log(getCheckedRows())

总和大
1.9995
总和小
1.9995
虎
1.9995
组数: 3.
总金额: 3.

这可以使用jquery完成。为了便于使用,我添加了一些td类

html:


是否可以在我的if-else条件下将其写入,而不定义新函数?是的,只需复制代码
var arr=[]$('table:checkbox:checked').each(function(){td=$(this).closest('tr').find('td');arr.push([$(td[0]).text(),$(td[1]).text(),$(td[2]).find('input').val());});控制台日志(arr)嗨,它工作了,我开始总和小,1.9995,11, 虎,1.9995,11 .. 我们能把逗号改成?喜欢总和小,1.9995,11; 虎,1.9995,11很抱歉这个愚蠢的请求。。。我只是个新手。。我们如何将这个arr.join(“;”)实现到您想要的代码中?
"确定": function(){
                var count = parseFloat($('#confirm-total-amount').html());
                if(!isNaN(count) && count == 0){
                    alert("Please enter money!");
                }else{ 
                    Combine single array here !!!!

                }
            },
<tbody id="confirm-table-body">
<tr>
    <td class="title"> 总和大</td>
    <td class="number" style="color: red">1.9995</td>
    <td class="money" style="padding: 3px 10px 3px 10px"><input value="1" style="width: 80px"></td>
    <td><input type="checkbox" checked=""></td>
</tr>
<tr>
    <td class="title"> 总和小</td>
    <td class="number" style="color: red">1.9995</td>
    <td class="money" style="padding: 3px 10px 3px 10px"><input value="1" style="width: 80px"></td>
    <td><input type="checkbox" checked=""></td>
</tr>
<tr>
    <td class="title"> 虎</td>
    <td class="number" style="color: red">1.9995</td>
    <td class="money" style="padding: 3px 10px 3px 10px"><input value="1" style="width: 80px"></td>
    <td><input type="checkbox" checked=""></td>
</tr>
<tr>
    <td colspan="2">组数: <span id="confirm-gropup-nums">3</span></td>
    <td colspan="2">总金额: <span id="confirm-total-amount">3</span></td>
</tr>
</tbody>
function(){
        var count = parseFloat($('#confirm-total-amount').html()),
            output = [];
        if (!isNaN(count) && count == 0) {
            alert("Please enter money!");
        } else { 
            $("td input[type=checkbox]:checked").each(function() {
                var $parent = $(this).parent();

                output.push({
                    "title": $parent.find(".title").html(),
                    "number": $parent.find(".number").html(), 
                    "money": $parent.find(".money input").val(),
                })
            })
        }
    }