dongpu1315 2014-04-14 08:48
浏览 59
已采纳

在php中更改所选选项的文本颜色

I want to change background color of selected option item in php but i coulnd do that. I only add an indicator(*) to begining of the selected option with bellow code but i am not exactly need that. I need to change text color of selected form item in php.

Adding style="background-color:red" to $a is works.!

<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>
  • 写回答

3条回答 默认 最新

  • dtvdz911959 2014-04-14 08:56
    关注

    append style="background-color:(yourColor)" to $a

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?