如何在javascript中更改颜色代码
嗨,伙计们,我试着从颜色词$Tcounter.csscolor,黑色输入一个颜色代码;在这个脚本中,从黑色到317D29。我该怎么做如何在javascript中更改颜色代码,javascript,jquery,css,Javascript,Jquery,Css,嗨,伙计们,我试着从颜色词$Tcounter.csscolor,黑色输入一个颜色代码;在这个脚本中,从黑色到317D29。我该怎么做 <script type="text/javascript"> $(document).ready(function() { var Tcharacters = <?php echo $max_character_length_title; ?>; $("#Tcounter").append("<small>&
<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");
}
});
</script>
谢谢如果要使用十六进制代码,请执行此操作
$t counter.csscolor,317D29 首先让我知道计数器是id或类 如果Tcounter是类,请使用:$.Tcounter.csscolor,ff0000 如果Tcounter是id,则使用:$Tcounter.csscolor,ff0000 $document.readyfunction{ $button.clickfunction{ $.Tcounter.csscolor,ff0000; $t计数器.csscolor,ADFF2F; }; };
使用类的红色
使用id的绿色
设置p的背景色还有…有什么问题吗?只需键入317D29而不是黑色。@Ansel Mae为什么$Tcounter.csscolor,317D29不起作用?不,它不起作用,但它在黑色时起作用?您上面的脚本甚至无效。此脚本将按预期工作。在对答案进行否决表决之前,请确保您的脚本有效。我发现错误,颜色是css文件中的默认颜色是的,它现在工作了,问题是css文件中的主体颜色。请参阅此,以了解css颜色代码是否使用相同的颜色。如果必须添加jquery脚本,请检查该脚本。