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

问题描述:

嗨,大家好,我想更改此行 $(“#Tcounter”).css(“color”,“red”); 在此脚本中使用颜色代码#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> 

更多有关此信息我不能给!

感谢

+0

您的浏览器控制台中有任何错误吗? – NewToJS

+0

如果我用“#BC0202”改变它,它仍然保持原来的颜色! – Rhoda

+0

我明白......您在浏览器控制台中显示任何错误吗? – NewToJS

简单,变化red#BC0202

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

+0

这不起作用代码不会改变颜色 – Rhoda

只是更换颜色相应十六进制代码的那种颜色的

+0

如果我这样做$ (“#Dcounter”).css(“color”,“#BC0202”);我收到stil红色 – Rhoda

+1

是的,因为这个十六进制代码属于强烈的红色,它会反映出来。 –