我有要插入单元格的行的对象
我无法做的是选择特定的column
来插入数据。
<ul class="my_list">
<li>
<h3 >Eusebio Rice</h3>
<ul class="my_sublist">
<li data-time="14:30:00" data-day="Sun">Discipline I</li>
<li data-time="14:30:00" data-day="Tue">Discipline II</li>
</ul>
</li>
</ul>
<table id="prof-table">
<tbody>
<tr>
<th>HORÁRIO</th>
<th data-dia="Sun">Sunday</th>
<th data-dia="Tue">Tuesday</th>
<th data-dia="Wed">Wednesday</th>
<th data-dia="Thu">Thursday</th>
<th data-dia="Fri">Friday</th>
</tr>
<tr>
<td>08:30 ~ 10:30</td>
</tr>
<tr>
<td>10:30 ~ 12:30</td>
</tr>
<tr>
<td>14:30 ~ 16:30</td>
</tr>
</tbody>
</table>
这是我迄今为止所做的:
$(document).ready(function(){
$(".my_list h3").click(function(event){
var obj = event.target;
//loop through all the disciplines and get their name and time
$(obj).next().find('li').each(function(){
var disciplina = $(this).text().trim();
var discipline_time = $(this).data('time');
var time_range = $('#prof-table').find("tr td:first-child"); //take the first column
var day_range = $('#prof-table').find("tr th");
time_range = time_range.map(function(idx, row){
var time_period = $(row).text().split(' ~ '); //split the columns data to start and stop time
//create a new object that keeps the time range and index
return {index: idx, from: time_period[0], to: time_period[1]};
});
.each(time_range, function(indx, range){
if( (range.from+":00")<= discipline_time && (range.to+"00") >= discipline_time){
var myRow = document.getElementById("prof-table").rows[range.index + 1]; //range.index pega rows
console.log(myRow); // My row element
那么,我怎么能做一些事情来循环一周的日子,并与纪律的一周比较。是的,可以在行的第3位插入一个单元而不必先将它插入位置1和2吗?如果它是唯一的方法,是否有更好的方法来代替for循环?