首页 > 解决方案 > 如何更改 IE 中几个禁用的选择字段的颜色

问题描述

我尝试了下面的代码来更改一些禁用的选择项的颜色,尽管它在 Chrome 中工作但在 IE 中没有。我尝试提供 ::ms-value,但它适用于所有不需要红色的禁用选择字段。有什么办法可以在 Jquery 中做到吗?css 也很好。谢谢

HTML

 <select class="select_red" disabled="">
    <option>--Select--</option>
    <option class="red">one</option>
    <option>two</option>
    <option class="red">three</option>
    <option>four</option>
 </select>

脚本

jQuery(document).on("change", ".select_red", function(event){
if($(this).find("option:selected").hasClass("red")){
    $(this).addClass("redtext");
}else {
    $(this).removeClass("redtext");
}

CSS

 .redtext{color:#f00 !important;}   
 .redtext, .select_red:disabled{color:#f00 !important;}

标签: htmljquerycss

解决方案


我不确定你能不能。每个浏览器都有自己的方式来设置这些样式。但是,您可以自己制作!


推荐阅读