我正在尝试将css规则应用于tr元素,具体取决于哪些类将是以下tr。jquery if语句检测是否存在具有“X”类的tr
ex。
<table>
<tr class="x"/>
<tr class="y"/>
<tr class="x"/>
<tr class="x"/>
</table>
因此,与类X具有与Y类跟随TR将具有比TR,未来TR是X类不同的CSS样式的TR。
<script type="text/javascript">
$(document).ready(function() {
if ($("tr.x").next('(tr.y)')) {
$(this).css({'background-color' : 'yellow', 'font-weight' : 'bolder'});
}
else{
$(this).css({'background-color' : 'blue', 'font-weight' : 'normal'});
}
});
</script>
它根本不工作,我不知道为什么。
任何帮助,将不胜感激。
在此先感谢。
更新
我想的CSS样式应用到TR的第一个TD,我试图;
$(this).first('td').css({ 'color': 'Blue',});
但仍然适用于行。
再次感谢所有。
我想将CSS样式应用于tr的第一个td,而我正在尝试; (this).first('td')。css({'color':'Blue',}); 但仍然适用于行 – Amra 2010-09-22 11:38:49
@Cesar:您正在寻找'td:first-child',我已经更新了答案。 – 2010-09-22 13:26:33
@ T.J。克劳德:感谢你的回复,我想我没有很好地解释自己,我需要将风格应用到每个通过条件的tr的第一个td。再次感谢。 – Amra 2010-09-22 13:45:27