我当前的 HTML
结构
<div class="pull-right" id="sandbox-container">
<div class="datepicker datepicker-inline">
<div class="datepicker-days">
<table class=" table-condensed"><thead>
<tr><th class="prev" style="visibility: visible;">«</th>
<th class="datepicker-switch" colspan="5">October 2014</th>
<th class="next" style="visibility: visible;">»</th></tr>
<tr>
<th class="dow">Mo</th>
<th class="dow">Tu</th>
<th class="dow">We</th>
<th class="dow">Th</th>
<th class="dow">Fr</th>
<th class="dow">Sa</th>
<th class="dow">Su</th>
</tr>
</thead>
<tbody>
<tr>
<td class="old day">29</td>
<td class="old day">30</td>
<td class="day">1</td>
<td class="day">2</td>
<td class="day">3</td>
<td class="disabled day">4</td>
<td class="disabled day">5</td>
</tr>
<tr>
<td class="day">6</td>
<td class="day">7</td>
<td class="day">8</td>
<td class="day">9</td>
<td class="day">10</td>
<td class="disabled day">11</td>
<td class="disabled day">12</td>
</tr>
<tr>
<td class="day">13</td>
<td class="day">14</td>
<td class="day">15</td>
<td class="day">16</td>
<td class="day">17</td>
<td class="disabled day">18</td>
<td class="disabled day">19</td>
</tr>
<tr><td class="day">20</td>
<td class="day">21</td>
<td class="day">22</td>
<td class="day">23</td>
<td class="day">24</td>
<td class="disabled day">25</td>
<td class="disabled day">26</td>
</tr>
<tr>
<td class="day">27</td>
<td class="day">28</td>
<td class="today day">29</td>
<td class="day">30</td>
<td class="day">31</td>
<td class="new disabled day">1</td>
<td class="new disabled day">2</td>
</tr>
<tr>
<td class="new day">3</td>
<td class="new day">4</td>
<td class="new day">5</td>
<td class="new day">6</td>
<td class="new day">7</td>
<td class="new disabled day">8</td>
<td class="new disabled day">9</td></tr>
</tbody>
<tfoot>
<tr>
<th class="today" colspan="7" style="display: none;">Today</th>
</tr>
<tr>
<th class="clear" colspan="7" style="display: none;">Clear</th>
</tr>
</tfoot>
</table>
</div>
</div>
</div>
在上面生成的HTML
中,有一个<td>
,其中today day
类是
<tr>
<td class="day">27</td>
<td class="day">28</td>
<td class="today day">29</td>
<td class="day">30</td>
<td class="day">31</td>
<td class="new disabled day">1</td>
<td class="new disabled day">2</td>
</tr>
如何将CSS类应用于其<tr>
,结果将是
<tr class="mycustomClass">
<td class="day">27</td>
<td class="day">28</td>
<td class="today day">29</td>
<td class="day">30</td>
<td class="day">31</td>
<td class="new disabled day">1</td>
<td class="new disabled day">2</td>
</tr>
课程today day
仅适用于一个<td>
。
感谢。
答案 0 :(得分:4)
您可以找到包含td
和today
类的day
,然后找到其父级tr
,并将类mycustomclass
添加到其中
$('td.today.day').parent().addClass('mycustomClass')
答案 1 :(得分:3)
试试这个:找到{= 1}},让class =“今天”并获取其父级添加td
mycustomClass
答案 2 :(得分:2)
$(".today.day").closest("tr").addClass("mycustomClass");
答案 3 :(得分:0)
使用类&#34;今天&#34;找到TD的父TR元素。和&#34; day&#34;并使用addClass()为其添加类。
您可以尝试以下方法,
$('td.today.day').parent('tr').addClass('YourClass')