【发布时间】:2018-03-22 22:10:48
【问题描述】:
我需要使用列id更改一组列的背景颜色。前两列背景不需要更改。在Jquery中如何实现? 这是我迄今为止尝试过的。我已在其中添加了我的完整脚本,您可以获得更多信息。
var fromtime = obj[i].FromTime; // Here fromtime gives id of a column not index
var totime = obj[i].totime; // Here totime gives id of a column not index
$(row1).children('td').slice(fromtime,totime).not('td:eq(0)').not('td:eq(0)').css({ "background-color": workcolor });
编辑: 我已经添加了我的 HTML 代码
<table class="table table-striped" id="table1">
<thead>
<tr>
<th class="" id="profilepic">Image</th>
<th id="empName">Employee</th>
<th id="00">00:00</th>
<th id="01">01:00</th>
<th id="02">02:00</th>
<th id="03">03:00</th>
<th id="04">04:00</th>
<th id="05">05:00</th>
<th id="06">06:00</th>
<th id="07">07:00</th>
<th id="08">08:00</th>
<th id="09">09:00</th>
<th id="10">10:00</th>
<th id="11">11:00</th>
<th id="12">12:00</th>
<th id="13">13:00</th>
<th id="14">14:00</th>
<th id="15">15:00</th>
<th id="16">16:00</th>
<th id="17">17:00</th>
<th id="18">18:00</th>
<th id="19">19:00</th>
<th id="20">20:00</th>
<th id="21">21:00</th>
<th id="22">22:00</th>
<th id="23">23:00</th>
</tr>
</thead>
<tbody id="body1">
</tbody>
完整的脚本:
$(row1).children('td').not('td:eq(0)').not('td:eq(0)').css({ "background-color": workcolor });
我每次都添加一个名为“row1”的新行,它的单元格背景颜色需要根据"fromtime" 到"ToTime" 值进行修改。使用Children('td') td 意味着整行都着色了。但是我只需要特定的细胞。
【问题讨论】:
-
HTML 也好吗?
-
请显示完整的脚本和html。
-
为什么不简单地使用
css和classes? jQuery/javascript 不是必需的 -
因为需要申请
background的列是动态的,他不知道哪一个需要class
标签: javascript jquery