简体   繁体   English

在“选择榆木”中更改所选项目的颜色-Firefox渲染问题

[英]Changing color of selected item in Select Elm - Firefox rendering issue

I simply am trying to add a color to the select item background within the select elm after a user makes a selection from the select elm. 我只是想在用户从选择榆木中进行选择后,在选择榆木中的选择项背景中添加颜色。 The result right now is that in firefox, the colors will change, but only during selection ... after the selection has been made the background for the individual selection is still white. 现在的结果是,在Firefox中,颜色将发生变化,但仅在选择期间会发生变化……选择完成后,单个选择的背景仍然是白色。

This code works fine in IE but so far my efforts have been thuarted in FireFox. 该代码在IE中可以正常工作,但到目前为止,我在FireFox中所做的工作已得到了广泛的应用。 Any suggestions would help. 任何建议都会有所帮助。

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();
    }

Ps I made an equivalent javascript method and made some attempts at it, but the result is still the same. 附言:我做了一个等效的javascript方法,并做了一些尝试,但结果仍然相同。 The background color of the item is changed ... but only is visible when making a selection, NOT after the selection is made. 该项的背景颜色已更改……但仅在进行选择时可见,而在选择后不可见。

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

.OtherThanSerious { background-color: #C2FF87; }

.Serious { background-color: #FFBC43; }

.Critical { background-color: #FF6743; }

Ah I get it. 啊,我明白了。

I don't think there is any agreed standard for styling of select elements, it's genarally seen as bad for usabilty to mess with default OS styles for it. 我认为选择元素的样式没有统一的标准,通常认为将其与默认操作系统样式混为一谈是不利的。

However you can change the color on the background if you attach your class directly to the select tag and not to the option tag. 但是,如果您将课程直接附加到选择标签而不是选择标签,则可以在背景上更改颜色。 But behaviour is probably quite erratic across browsers. 但是跨浏览器的行为可能很不稳定。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM