為什么59分沒有標紅,復制了答案上的代碼
d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59 }
def generate_tr(name, score):
? ? if score < 60:
? ? ? ? return '<tr><td>%s</td><td style="color:red">%s</td></tr>' % (name, score)
? ? return '<tr><td>%s</td><td>%s</td></tr>' % (name, score)
tds = [generate_tr(name, score) for name, score in d.iteritems()]
print '<table border="1">'
print '<tr><th>Name</th><th>Score</th><tr>'
print '\n'.join(tds)
print '</table>'
2019-08-29
這是內聯樣式, 應該比其他選擇器的優先級高, 可能是瀏覽器版本的問題把, 你可以試試下面代碼
在td內在嵌套一層標簽, 這個我測試過, 可行的