javascript 我可以在 IE 中更改禁用的 HTML 选择元素的颜色吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14003679/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 20:28:00  来源:igfitidea点击:

Can I change the color of Disabled HTML Select Element in IE?

javascriptjqueryhtmlcss

提问by user960567

I have a requirement of changing the color of a html select. I have search a lot but was not find a sample that works in IE. So, can I change the color of Disabled HTML Select Element in IE? I need a sample, in css or javascript or in jquery. Here is what I have tried.

我需要更改 html 选择的颜色。我搜索了很多,但没有找到在 IE 中工作的示例。那么,我可以在 IE 中更改 Disabled HTML Select Element 的颜色吗?我需要一个示例,在 css 或 javascript 中或在 jquery 中。这是我尝试过的。

<select disabled="disabled">
    <option value="a">option A</option>
    <option value="b">option B</option>
    <option value="c">option C</option>
</select>

[disabled] {
  color: #933;
  background-color: #ffc;
}


select:disabled
{
    border: solid 1px silver;
    background-color: #F9F9F9;
    color:blue;
}


[disabled] option {
    background-color: #ffc;  color: #933;
}

回答by Jon Grant

The solution is to use the ::-ms-valueselector:

解决方案是使用::-ms-value选择器:

select[disabled]::-ms-value {
    color: red;
}

回答by algorhythm

try

尝试

[disabled="disabled"] {
    color: #933;
    background-color: #ffc;
}

or

或者

*[disabled="disabled"] {
    color: #933;
    background-color: #ffc;
}

or

或者

select[disabled="disabled"] {
    color: #933;
    background-color: #ffc;
}

or with jQuery

或使用 jQuery

<script type="text/javascript">
    jQuery(document).ready(function() {
        jQuery('[disabled="disabled"]').css({ 'color': '#993333', 'background-color': '#ffffcc' });
    });
</script>

回答by Kolob Canyon

In fact, none of the above/below answers worked for me, but this did:

事实上,以上/以下答案都不适合我,但这确实适用:

# Select all disabled DOM objects
$(':disabled').css({
    color:'red'
});

# Select disabled DOM objects by HTML tag <input>
$('input:disabled').css({
    color:'red'
});

For more information: https://api.jquery.com/disabled-selector/

更多信息:https: //api.jquery.com/disabled-selector/