Change color of disabled radiobutton list element

2019-08-22 07:34发布

问题:

I've got a radiobuttonlist with a bunch of list items, some of them disabled. The label control beside the radio button turns gray, which can be hard to read. How do I change the color of the label? I've tried CSS, changing the forecolor - nothing seems to work:

currentButton.Attributes.Add("class", "disabled");

Any ideas?

回答1:

Although I've never used asp.net built-in controls, I'm guessing here that your RadioButtonList is trying to be smart enough and renders some CSS (inline or class/id) to visually reflect its control state.

You should take a look at the generated HTML and spot such CSS code then try to override it. If they designed that control the way I think, maybe there's a property that lets you change that particular state color. But if there isn't such a property, you always have the option to override that with your custom CSS.

If the CSS is rendered inline (blame MS for that LOL) post back here and I'll try to get back with a workaround.



回答2:

You can use the CSS attribute selector for this:

input.myclass[disabled=disabled] { color: #FF0000; }

Update: Fixed the answer since I misunderstood the question.



回答3:

    $(document).ready(function() {
        setRadioButtonListStyle();
    });

    function setRadioButtonListStyle() {
        var radioButtonListServerId = "rblOption";
        var labels = $("label[for*='" + radioButtonListServerId + "']");
        $.each(labels, function() {
            this.parentElement.disabled = false;
            }
        });

        var tables = $("table[id*='" + radioButtonListServerId + "']");
        $.each(tables, function() {
            this.disabled = false;
        });
    }