大家好我尝试从颜色词$("#Tcounter").css("color","black")
输入一个颜色代码编号;在此脚本中,从"black"
到"#317D29"
。我怎样才能做到这一点?
<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>
由于
答案 0 :(得分:0)
首先让我知道Tcounter是id或class。
如果Tcounter是课堂使用:$(".Tcounter").css("color","#ff0000");
如果Tcounter是id,则使用:$("#Tcounter").css("color","#ff0000");
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$(".Tcounter").css("color","#ff0000");
$("#Tcounter").css("color","#ADFF2F");
});
});
</script>
</head>
<body>
<p class="Tcounter">Red Color using class</p>
<p id="Tcounter" >Green Color using Id</p>
<button >Set background-color of p</button>
</body>
</html>
&#13;
答案 1 :(得分:-1)
如果您想使用十六进制代码,请执行此操作。
$(&#34;#Tcounter&#34)的CSS。(&#34;颜色&#34;&#34;#317D29&#34);