[英]Windows desktop gadget RSS Feed colour coding items
我有一個桌面小工具,可以從網站上提取RSS Feed。 Feed中包含有關問題的信息-即 優先級,時間,說明。
Feed項顯示在桌面上-但是我需要根據它們的優先級對它們進行顏色編碼,即使用substr函數對它們進行顏色編碼-例如1 =紅色-是否有更好的方法使用JavaScript / HTML?
目前,我已將其歸納在一起-但是還有更優雅的解決方案嗎?
if (feed.item.description.substr(10,1) == "1")
{
document.write "<a href colour="red"" + item + ">";
else if (feed.item.description.substr(10,1) == "2")
{
document.write "<a href colour="yellow"" + item + ">";
else
{
document.write "<a href colour="green"" + item + ">";
為什么不使用CSS? 根據優先級或其他內容為錨標記提供一個類(或多個類),然后使用CSS文件驅動樣式。
document.write("<a href='(whatever)' class="description_" + feed.item.description.substr(10, 1));
或類似的東西。 然后您的CSS文件會說
a.description_1 { color: red; }
a.description_2 { color: yellow; }
等等
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.