【问题标题】:Windows desktop gadget RSS Feed colour coding itemsWindows 桌面小工具 RSS Feed 颜色编码项目
【发布时间】:2010-05-20 00:07:28
【问题描述】:

我有一个桌面小工具,可以从网站提取 RSS 源。提要包含有关问题的信息 - 即。优先级、时间、描述。

Feed 项目显示在桌面上 - 但是我需要根据它们的优先级对它们进行颜色编码,即 1 = 红色等。使用 substr 函数 - 有没有更好的方法来使用 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 + ">";

【问题讨论】:

    标签: javascript html windows-desktop-gadgets


    【解决方案1】:

    为什么不使用 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; }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-10-10
      • 1970-01-01
      • 2013-01-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多