简体   繁体   English

针对表格中的每个单元格

[英]target each cell in a table

I have a table and each row represents a different math percentage grouping and each cell needs to show the high end and low end for each math equation. 我有一张表,每一行代表一个不同的数学百分比分组,每个单元格需要显示每个数学方程式的高端和低端。 I need to iterate through the table rows then loop through the cells. 我需要遍历表行,然后遍历单元格。 And preform diffent math in each cell. 并在每个单元格中执行不同的数学运算。 ie: row[0] cell[1] = 1+2 , row[0] cell[2] = 2+4 ... I have attached an image of my table [table][1] . 即: row[0] cell[1] = 1+2row[0] cell[2] = 2+4 ...我已经附上了我的桌子[table][1]

<table class="table table-condensed table-bordered">
    <thead>
    <tr>
        <th class="noColor"></th>
        <th class="noColor">Low End</th>
        <th class="noColor">High End</th>
    </tr>
    </thead>
    <tbody id="tbody">
    <tr>
        <td>31%-40%</td>
        <td>-</td>
        <td>-</td>
    </tr>
    <tr>
        <td>41%-45%</td>
        <td>-</td>
        <td>-</td>
    </tr>
    <!-- .. and so on .. -->
    </tbody>
</table>

Here is my For Loop: 这是我的For循环:

 var tableRows = $('#tbody').find("tr");
    for(var i = 0; i < tableRows.length; i++) {
        var tableCell = tableRows.find("td");
        for(var j = 0; j < tableCell.length; j++) {
            [here is where Im confused]
        }
    }

I need to skip over the first cell in each row and preform a completely different math equation in cell 2 and 3 for each row and each row has a different math. 我需要跳过每行的第一个单元格,并在每行的单元格2和3中执行一个完全不同的数学方程式,并且每行都有不同的数学运算。

First row - cell 2 = total * 31% | 第一行-单元格2 =总计* 31%| cell 3 = total * 40% 单元格3 =总计* 40%

Second row - cell 2 = total * 41% | 第二行-单元格2 =总计* 41%| cell 3 = total * 45% 储存格3 =总计* 45%

and so on... 等等...

Thank you for you time and sorry for my rookieness 谢谢您的时间,也很抱歉我的菜鸟

Hey I need more information to help you out further but here is how you can select the inside of the element. 嘿,我需要更多信息来进一步帮助您,但是这里是您如何选择元素内部的方法。 Tell me what you need done from here step by step in a very specific and clear way and I'll do my best. 告诉我您需要从这里以一种非常明确和明确的方式逐步完成的事情,我会尽力而为。

 var tableRows = $('#tbody').find("tr");
    for(var i = 0; i < tableRows.length; i++) {
        var tableCell = tableRows[i].childNodes;
        for(var j = 0; j < tableCell.length; j++) {
            var currentRow = tableRows[i];
            var currentCell = tableCell[j].innerHTML;

            console.log(currentCell)

        }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM