【问题标题】:Change text color of selected option item in php在php中更改所选选项的文本颜色
【发布时间】:2014-05-28 03:47:10
【问题描述】:

我想更改 php 中选定选项项的背景颜色,但我可以这样做。我只使用下面的代码在所选选项的开头添加一个指示符(*),但我并不完全需要它。我需要在 php 中更改所选表单项的文本颜色。

将 style="background-color:red" 添加到 $a 是可行的。!

<select name="dest">
                            <?php


                            $a='';
                            $sql2 = "select evaperiod from evaluationperiod";
                            $query2 = mysql_query($sql2);

                            if(mysql_num_rows($query2)>0)
                            {
                                $x='20';
                                $guncel='';
                                while($result=mysql_fetch_array($query2))
                                {
                                    $period = $result['evaperiod']; 
                                    if($period==$donemm)
                                    $a=" selected='selected' style='background-color:red'";
                                    if($period==$periodd)
                                    $guncel='*';
                                    else
                                    $a='';
                                    print "<option value='$period'$a>$guncel$x$period</option>";
                                    $guncel='';
                                }   
                            } ?>

                        </select>

【问题讨论】:

标签: php css select colors option


【解决方案1】:

为选定对象添加 CSS 样式

option[selected='selected'] {
    background:red;
    font-color: blue;
}

【讨论】:

    【解决方案2】:

    style="background-color:(yourColor)" 附加到$a

    【讨论】:

      【解决方案3】:

      附加到 $guncel 变量 this:

      style="background:gray"
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-03-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-01-12
        • 2011-12-06
        • 2014-02-05
        相关资源
        最近更新 更多