Change color of disabled radiobutton list element

落爺英雄遲暮 提交于 2019-12-24 22:58:18

问题


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


来源:https://stackoverflow.com/questions/1189760/change-color-of-disabled-radiobutton-list-element

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!