我有下面的JS,它根据表1的值修改表2的单元格中的数值。但是,在表1中有一些值为“OFF”的单元格,这会弄乱我的数字其余的细胞。我想我需要另一个变量“OFF”但我无法在经过多次测试后运行它。有什么想法吗?
干杯。
var t1 = document.getElementById('mytable1');
var t2 = document.getElementById('mytable2');
for (x = 1; x <= 5; x++) { //Loop through the days(columns)
for (y = 1; y < t1.rows.length; y++) { //Loop through the people(rows)
var cell1 = t1.rows[y].cells[x].innerHTML;
var start = cell1.split(' - ')[0];
var stop = cell1.split(' - ')[1];
var starttime = new Date('', '', '', start.split(':')[0], start.split(':')[1]);
var stoptime = new Date('', '', '', stop.split(':')[0], stop.split(':')[1]);
var starttime2 = new Date('', '', '', starttime.getHours() - 7, starttime.getMinutes());
var stoptime2 = new Date('', '', '', stoptime.getHours() - 7, stoptime.getMinutes());
t2.rows[y].cells[x].innerHTML = ((starttime2.getHours() < 10) ? "0" : "") + starttime2.getHours() + ':' + ((starttime2.getMinutes() < 10) ? "0" : "") + starttime2.getMinutes() + ' - ' + ((stoptime2.getHours() < 10) ? "0" : "") + stoptime2.getHours() + ':' + ((stoptime2.getMinutes() < 10) ? "0" : "") + stoptime2.getMinutes();
}
}
HTML:
<table width=600px id="mytable1">
<tr>
<td>GMT</td>
<td>Monday</td>
<td>Tuesday</td>
<td>Wednesday</td>
<td>Thursday</td>
<td>Friday</td>
</tr>
<tr>
<td>Person A</td>
<td>OFF</td>
<td>17:00 - 01:30</td>
<td>09:00 - 17:30</td>
<td>17:00 - 01:30</td>
<td>09:00 - 17:30</td>
</tr>
<tr>
<td>Person B</td>
<td>09:00 - 17:30</td>
<td>17:00 - 01:30</td>
<td>OFF</td>
<td>17:00 - 01:30</td>
<td>09:00 - 17:30</td>
</tr>
<tr>
<td>Person C</td>
<td>09:00 - 17:30</td>
<td>17:00 - 01:30</td>
<td>09:00 - 17:30</td>
<td>17:00 - 01:30</td>
<td>09:00 - 17:30</td>
</tr>
<tr>
<td>Person D</td>
<td>09:00 - 17:30</td>
<td>17:00 - 01:30</td>
<td>09:00 - 17:30</td>
<td>17:00 - 01:30</td>
<td>09:00 - 17:30</td>
</tr>
</table>
<br />
<table width=600px id="mytable2">
<tr>
<td>GMT -7 Time</td>
<td>Monday</td>
<td>Tuesday</td>
<td>Wednesday</td>
<td>Thursday</td>
<td>Friday</td>
</tr>
<tr>
<td>Person A</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>Person B</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>Person C</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>Person D</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>