我已經開始學習jQuery,並且我是trying來設置tr
的color
,但無法這樣做。不過,我可以成功更新其他css屬性,例如font-style
。從我學到的至今設置的CSS屬性和值我們使用:無法使用jQuery設置顏色
$(selector).css(property,value)
所以,請指出錯誤。
HTML:
<table class="csr">
<tr><td>Row 1</td></tr>
<tr><td>Row 2</td></tr>
<tr><td>Row 3</td></tr>
</table>
<table class="aTable">
<tr><td>Row 11</td></tr>
<tr><td>Row 22</td></tr>
<tr><td>Row 33</td></tr>
</table>
CSS:
td {
color: blue;
font-weight: bold;
}
table.aTable td{
color: red;
font-weight: bold;
}
的jQuery:
$("tr:first").css("font-style", "italic");
$("tr:first").css("color", "red");
$("tr:first").css("background-color","yellow");
$(".aTable tr:first").css("font-style", "italic");
$(".aTable tr:first").css("background-color","yellow");
你的代碼看起來有效,你可以試試官方的例子嗎?也許嘗試一步一步的修改,並觀察差異:) http://api.jquery.com/first-selector/ – petrbel 2014-10-31 07:13:49
您可以將'tr'顏色更改爲'紅色',但'td'仍然具有'藍色'顏色組。 – Justinas 2014-10-31 07:14:13
@Justinas thnx改爲'$(「td:first」).css(「color」,「red」)'做了這個工作 – KNU 2014-10-31 07:15:39