在Select Elm - Firefox渲染问题中更改所选项目的颜色

时间:2010-12-06 20:53:27

标签: javascript asp.net css firefox

我只是在用户从选择榆树中进行选择后,尝试在选择榆树中为选择项目背景添加颜色。现在的结果是,在firefox中,颜色会发生变化,但仅在选择期间...选择完成后,单个选择的背景仍为白色。

此代码在IE中运行良好,但到目前为止,我的努力已在FireFox中得到了解决。任何建议都会有所帮助。

public static void PerformDDLBackgroundChange(SDropDownList ddl)
    {
        switch ((ComplianceLevel)int.Parse(ddl.SelectedValue))
        {
            case ComplianceLevel.Compliant:
                ddl.SelectedItem.Attributes.Add("class", "Compliant");
                break;
            case ComplianceLevel.OtherThanSerious:
                ddl.SelectedItem.Attributes.Add("class", "OtherThanSerious");
                break;
            case ComplianceLevel.Serious:
                ddl.SelectedItem.Attributes.Add("class", "Serious");
                break;
            case ComplianceLevel.Critical:
                ddl.SelectedItem.Attributes.Add("class", "Critical");
                break;
        }
        ddl.Update();
    }

P.s我做了一个等效的javascript方法并对它进行了一些尝试,但结果仍然相同。项目的背景颜色已更改...但仅在进行选择时可见,而不是在选择后显示。

.Compliant { background-color : #8AC9FF; }

.OtherThanSerious { background-color: #C2FF87; }

.Serious { background-color: #FFBC43; }

.Critical { background-color: #FF6743; }

1 个答案:

答案 0 :(得分:1)

啊,我明白了。

我认为对于选择元素的样式没有任何商定的标准,它通常被视为对于使用它的默认操作系统样式的可用性不利。

但是,如果将类直接附加到选择标记而不是选项标记,则可以更改背景颜色。但是不同浏览器的行为可能相当不稳定。