更改所选选项的颜色 - jQuery [英] Change color of option selected - jQuery

查看:91
本文介绍了更改所选选项的颜色 - jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要更改所选的选项=selected的文字颜色:

I want to change the text color of the option that is selected="selected":

    <select class="select">
        <option value="--">--</option>
        <option value="2014">2014</option>
        <option value="2013">2013</option>
        <option value="2012" selected="selected">2012</option>
        <option value="2011">2011</option>
    </select>

我一直在尝试CSS,但似乎不可能:

I have been trying with CSS but it seems its not possible:

    .select select [selected="selected"]{
        color: #2b2b2b;
    }

有jQuery的想法吗?

Any ideas with jQuery?

推荐答案

我一直在试用CSS,但似乎不可能:

I have been trying with CSS but it seems its not possible:

您要定位选择标记,而不是选项标记,那么选择器意味着选择任何 select 元素嵌套在 .select class

Because you are targetting the select tag and not option tag also, that selector means select any select element nested inside element having .select class

select option[selected] {
    color: red;
}

演示

您正在使用 class 选择器像

.select option[selected] {
   color: red;
}

这篇关于更改所选选项的颜色 - jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆