0

我正在尝试使用以下代码将不同的样式应用于某个类下方的每个第一表行:

$(".my-class tr:first td").css({"color":"#0064CC","font-size":"15px","border-bottom-style":"none"});

问题是它只将它应用于它在该类下面找到的第一个表。

我在这里想念什么?

4

4 回答 4

2

Try the following :

$(".my-class").find("tr:first td").css({"color":"#0064CC","font-size":"15px","border-bottom-style":"none"});

Your previous code was only finding the first row and td, this will find every element with .my-class and find the first tr/td element of the found elements.

于 2013-10-09T09:34:57.760 回答
1

您也可以尝试精确

$(".my-class").find("tr td:eq(0)").css({"color":"#0064CC","font-size":"15px","border-bottom-style":"none"});
于 2013-10-09T09:41:44.243 回答
1

改变

 $(".my-class tr:first td")

$("table tr:first").has('.my-class').find('td')
于 2013-10-09T09:44:48.617 回答
0

尝试这样的事情

$(".my-class tr:first td").each(function(){
    $(this).css({"color":"#0064CC","font-size":"15px","border-bottom-style":"none"});
})
于 2013-10-09T09:41:20.687 回答