如何更改脚本中的颜色代码

时间:2017-04-16 09:01:05

标签: javascript php

大家好我想改变这一行     $( “#Tcounter”)的CSS( “颜色”, “红”)。 在此脚本中使用颜色代码#BC0202,我该如何做?

<script type="text/javascript">
$(document).ready(function()  {
    var Tcharacters = <?php echo $max_character_length_title; ?>;
        $("#Tcounter").append("<small><?php osc_esc_js(_e('You have','ctg_housing')); ?> <strong>"+  Tcharacters+"</strong> <?php osc_esc_js(_e('characters remaining','ctg_housing')); ?></small>");
        $("#title<?php echo osc_current_user_locale(); ?>").keyup(function(){
    if($(this).val().length > Tcharacters){
        $(this).val($(this).val().substr(0, Tcharacters));
        }
    var Tremaining = Tcharacters -  $(this).val().length;
        $("#Tcounter").html("<small><?php osc_esc_js(_e('You have','ctg_housing')); ?> <strong>"+  Tremaining+"</strong> <?php osc_esc_js(_e('characters remaining','ctg_housing')); ?></small>");
    if(Tremaining <= 10)
    {
        $("#Tcounter").css("color","red");
        }
    else
    {
        $("#Tcounter").css("color","black");
        }
    });

    var Dcharacters = <?php echo $max_character_length_description; ?>;
        $("#Dcounter").append("<small><?php osc_esc_js(_e('You have','ctg_housing')); ?> <strong>"+  Dcharacters+"</strong> <?php osc_esc_js(_e('characters remaining','ctg_housing')); ?></small>");
        $("#description<?php echo osc_current_user_locale(); ?>").keyup(function(){
    if($(this).val().length > Dcharacters){
        $(this).val($(this).val().substr(0, Dcharacters));
    }
    var Dremaining = Dcharacters -  $(this).val().length;
        $("#Dcounter").html("<small><?php osc_esc_js(_e('You have','ctg_housing')); ?> <strong>"+  Dremaining+"</strong> <?php osc_esc_js(_e('characters remaining','ctg_housing')); ?></small>");
    if(Dremaining <= 10)
    {
        $("#Dcounter").css("color","red");
        }
    else
    {
        $("#Dcounter").css("color","black");
        }
    });
});
</script>

关于这个的更多信息我不能给!

由于

2 个答案:

答案 0 :(得分:2)

简单,将red更改为#BC0202

&#13;
&#13;
$("#Tcounter").css("color","#BC0202");
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div id="Tcounter">Foobar</div>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

替换颜色名称,使用相应的十六进制代码