我在我的CSS文件中定義的樣式如何改變TD的文字顏色爲紅色
我想申請這種風格,如果在我的
<tr>
<td class="lalign"><span class="ceoName"></span><span class="ceoTitle" style="color: navy;text-align: center;"></span></td>
<td><span class="ceoMondaySchedule"></span></td>
<td><span class="ceoTuesdaySchedule"></span></td>
<td><span class="ceoWednesdaySchedule"></span></td>
<td><span class="ceoThursdaySchedule"></span></td>
<td><span class="ceoFridaySchedule"></span></td>
</tr>
<tr>
<td class="lalign"><span class="cfoName"></span><span class="cfoTitle" style="color: navy;text-align: center;"></span></td>
<td><span class="cfoMondaySchedule"></span></td>
<td><span class="cfoTuesdaySchedule"></span></td>
<td><span class="cfoWednesdaySchedule"></span></td>
<td><span class="cfoThursdaySchedule"></span></td>
<td><span class="cfoFridaySchedule"></span></td>
</tr>
<tr>
<td class="lalign"><span class="ctoName"></span><span class="ctoTitle" style="color: navy;text-align: center;"></span></td>
<td><span class="ctoMondaySchedule"></span></td>
<td><span class="ctoTuesdaySchedule"></span></td>
<td><span class="ctoWednesdaySchedule"></span></td>
<td><span class="ctoThursdaySchedule"></span></td>
<td><span class="ctoFridaySchedule"></span></td>
</tr>
文中說無時間表設置
<style type="text/css">
td.mytdclass {
color: white;
background-color: red;
}
</style>
否則,我想用這種風格
<style>
td.mytdclass {
color: black;
}
</style>
我在客戶端使用jQuery。
我可以寫
$('.ceoMondaySchedule').each(function(idx, obj) {
var txt = $(this).text();
console.log(txt);
if (txt === "No Schedule Set" + "No Schedule Set") {
$(this).css('color', 'red');
} else {
$(this).css('color', 'black');
}
});
$('.ceoTuesdaySchedule').each(function(idx, obj) {
var txt = $(this).text();
console.log(txt);
if (txt === "No Schedule Set" + "No Schedule Set") {
$(this).css('color', 'red');
} else {
$(this).css('color', 'black');
}
});
$('.ceoWednesdaySchedule').each(function(idx, obj) {
var txt = $(this).text();
console.log(txt);
if (txt === "No Schedule Set" + "No Schedule Set") {
$(this).css('color', 'red');
} else {
$(this).css('color', 'black');
}
});
,並繼續做下去了所有5個天,然後做同樣的CFO則CTO
但有沒有寫這更好的辦法?
的[應用CSS樣式跨越基於內容標籤]可能的複製(http://stackoverflow.com/questions/31207051/apply-css-style-to-span-tag-based-on-content ) – coreyward
我們如何知道是否設定了時間表? – Dekel
您的CSS中不能有'td.mytdclass'兩種不同的樣式。 – Barmar