如何更改脚本中的颜色代码
嗨,大家好,我想更改此行 $(“#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>
更多有关此信息我不能给!
感谢
简单,变化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>
这不起作用代码不会改变颜色 – Rhoda
只是更换颜色名相应十六进制代码的那种颜色的。
如果我这样做$ (“#Dcounter”).css(“color”,“#BC0202”);我收到stil红色 – Rhoda
是的,因为这个十六进制代码属于强烈的红色,它会反映出来。 –
您的浏览器控制台中有任何错误吗? – NewToJS
如果我用“#BC0202”改变它,它仍然保持原来的颜色! – Rhoda
我明白......您在浏览器控制台中显示任何错误吗? – NewToJS