JQuery:find tr(class = x)get td(class = y)count td变量和属性,相应地改变tr

时间:2014-03-02 07:14:57

标签: javascript jquery html css jquery-ui

<table class="tbl">
<tr>td class= "colorcode" colspan ="5"/><tr>
<tr class="ms.alternative>
<td></td>
<td class="bkcolor"></td>
<td class="bkcolor"></td>
<td class="bkcolor"></td>
<td> </td>
</tr>
<tr><td colspan="5"/></tr>


 <tr>td class= "colorcode" colspan ="5"/><tr>
<tr class="ms.alternative>
<td></td>
<td class="bkcolor"></td>
<td class="bkcolor"></td>
<td class="bkcolor"></td>
<td></td>
</tr>
<tr><td colspan="5"/></tr>


<tr>td class= "colorcode" colspan ="5"/><tr>
<tr class="ms.alternative>
<td></td>
<td class="bkcolor"></td>
 <td class="bkcolor"></td>
<td class="bkcolor"></td>
<td></td>
</tr>
<tr><td colspan=""/></tr>

</table>

我是jquery的新手..请帮我弄清楚。

在上面的场景中:

现在我的问题是:您如何选择所有tr

class ms.alternative than find(td.bkcolor)
get the color of <td.bkcolor>

现在,如果:

 (number of majority of background color of '`tr.ms.alternative`' '`td.bkcolor`' 
 is red)
 {
     change td.colorcode.css(background-color:'red')
 }

1 个答案:

答案 0 :(得分:0)

$('tr[class="ms.alternative"]').find('td[class="bkcolor"]').css("background-color");

将为您提供背景颜色

 $('tr[class="ms.alternative"]').find('td[class="bkcolor"]').css("background-color","new color");

将更改您案例中的背景颜色