Javascript 使用jquery第n个子项时循环未正确执行

Javascript 使用jquery第n个子项时循环未正确执行,javascript,jquery,while-loop,Javascript,Jquery,While Loop,我尝试使用while loop获取td的背景色。但是代码不会执行 我需要循环直到得到“白色”作为背景色 这是我尝试过的: while ($(row1).children('td:nth-child(' + startIndex + ')').css('background-color') == 'rgba(0,0,0,0)') { startIndex = startIndex + 1; } while ($(row1).children('td:nth-child(' + endI

我尝试使用
while loop
获取
td
背景色。但是代码不会执行

我需要循环直到得到“白色”作为背景色

这是我尝试过的:

while ($(row1).children('td:nth-child(' + startIndex + ')').css('background-color') == 'rgba(0,0,0,0)') {

    startIndex = startIndex + 1;
}

while ($(row1).children('td:nth-child(' + endIndex + ')').css('background-color') == 'rgba(0,0,0,0)') {

    endIndex = endIndex - 1;
}
HTML代码:

 <thead>
                    <tr>

                        <th id="profilepic" data-tag="Image" style="text-align:center;min-width:50px">Image</th>
                        <th id="empName" data-tag="Employee" style="text-align:center;min-width:50px">Employee</th>
                        <th id="0000">00:00</th>
                        <th id="0030">00:30</th>
                        <th id="0100">01:00</th>
                        <th id="0130">01:30</th>
                        <th id="0200">02:00</th>
                        <th id="0230">02:30</th>
                        <th id="0300">03:00</th>
                        <th id="0330">03:30</th>
                        <th id="0400">04:00</th>
                        <th id="0430">04:30</th>
                        <th id="0500">05:00</th>
                        <th id="0530">05:30</th>
                        <th id="0600">06:00</th>
                        <th id="0630">06:30</th>
                        <th id="0700">07:00</th>
                        <th id="0730">07:30</th>
                        <th id="0800">08:00</th>
                        <th id="0830">08:30</th>
                        <th id="0900">09:00</th>
                        <th id="0930">09:30</th>
                        <th id="1000">10:00</th>
                        <th id="1030">10:30</th>
                        <th id="1100">11:00</th>
                        <th id="1130">11:30</th>
                        <th id="1200">12:00</th>
                        <th id="1230">12:30</th>
                        <th id="1300">13:00</th>
                        <th id="1330">13:30</th>
                        <th id="1400">14:00</th>
                        <th id="1430">14:30</th>
                        <th id="1500">15:00</th>
                        <th id="1530">15:30</th>
                        <th id="1600">16:00</th>
                        <th id="1630">16:30</th>
                        <th id="1700">17:00</th>
                        <th id="1730">17:30</th>
                        <th id="1800">18:00</th>
                        <th id="1830">18:30</th>
                        <th id="1900">19:00</th>
                        <th id="1930">19:30</th>
                        <th id="2000">20:00</th>
                        <th id="2030">20:30</th>
                        <th id="2100">21:00</th>
                        <th id="2130">21:30</th>
                        <th id="2200">22:00</th>
                        <th id="2230">22:30</th>
                        <th id="2300">23:00</th>
                        <th id="2330">23:30</th>
                    </tr>
                </thead>
                <tbody id="body1"></tbody>
//Here Iam appending the Row using Jquery
            </table>

形象
雇员
00:00
00:30
01:00
01:30
02:00
02:30
03:00
03:30
04:00
04:30
05:00
05:30
06:00
06:30
07:00
07:30
08:00
08:30
09:00
09:30
10:00
10:30
11:00
11:30
12:00
12:30
13:00
13:30
14:00
14:30
15:00
15:30
16:00
16:30
17:00
17:30
18:00
18:30
19:00
19:30
20:00
20:30
21:00
21:30
22:00
22:30
23:00
23:30
//这里我使用Jquery追加行

row1
变量还是类/id?row1是当前使用JQUERY追加的行如果
$(row1)
tr
,是否确定它有
tr
元素作为子元素?请添加完整的HTML+JQUERY代码。当前的代码很难理解您的问题,您是对的。这是我当前添加到表中的一行。完整的Html代码也有点冗长和不相关。。