【发布时间】:2016-06-12 16:27:02
【问题描述】:
我遇到了一个挑战,即根据 th 类更改 td 元素的背景颜色。下面是 html 代码,其中有名为 bots 的 th 类,我必须更改 td 下面所有元素的背景颜色strong>机器人类。
<table border="1" class="CSSTableGenerator" id="myTable">
<tr>
<th>Component</th>
<th>Properties</th>
<th class="bots">J10</th>
<th>J11</th>
<th>J12</th>
<th>J13</th>
</tr>
<tr>
<td>GenerateAlternateTagUrlDroplet</td>
<td>alternateTagConfiguration</td>
<td class="trueValue">/com//jec/website/seo/</td>
<td class="trueValue">/com//jec/website/seo/</td>
<td class="trueValue">/com//jec/website/seo/</td>
<td class="trueValue">/com//jec/website/seo/</td>
</tr>
<tr>
<td>AlternateTagUrlDroplet</td>
<td>tagConfiguration</td>
<td class="trueValue">/jec/website/seo/</td>
<td class="trueValue">/jec/website/seo/</td>
<td class="trueValue">/jec/website/seo/</td>
<td class="trueValue">/jec/website/seo/</td>
</tr>
</table>
有人可以帮助我使用 jquery 代码来实现这一点吗?
非常感谢。
【问题讨论】:
-
嗨,你能提供你当前的 CSS 吗?
-
感谢 Caelan 对此进行调查。好吧,我没有合适的CSS。我只是使用 jquery $('.trueValue').addClass('foo'); 动态添加类在我的 css 文件中,我正在设置这样的背景颜色 .foo {background-color: green;}。这仅适用于 td 元素。
标签: javascript jquery html css