我想更改html(username + ' is already exist. Please try another one');
的字体颜色
但我不知道如何改变这一点。
function check_availability(){
//get the username
var username = $('#username').val();
//use ajax to run the check
$.post("<?php echo base_url();?>loginFunction/checkUsername", { username: username },
function(result){
//if the result is 1
if(result == 1){
//show that the username is available
$('#username_availability_result').html(username + ' is Available');
}else{
//show that the username is NOT available
$('#username_availability_result').html(username + ' is already exist. Please try another one');
}
});
答案 0 :(得分:1)
尝试使用css
-
$('#username_availability_result')
.css('color', 'red')
.html(username + ' is already exist. Please try another one');
答案 1 :(得分:0)
<script>
$('#username_availability_result').css("color","red");
<script>
答案 2 :(得分:0)
您可以将其包含在span标记中。
function check_availability(){
//get the username
var username = $('#username').val();
//use ajax to run the check
$.post("<?php echo base_url();?>loginFunction/checkUsername", { username: username },
function(result){
//if the result is 1
if(result == 1){
//show that the username is available
$('#username_availability_result').html(username + ' is Available');
}else{
//show that the username is NOT available
$('#username_availability_result').html('<span style="color:#f00;">' + username + ' is already exist. Please try another one</span>');
}
});
}
答案 3 :(得分:0)
您还可以使用jQuery attr
:
$('#username_availability_result').attr('style','color:red');
$('#username_availability_result').html(username + ' is already exist. Please try another one');
答案 4 :(得分:0)
尝试这个
function check_availability(){
//get the username
var username = $('#username').val();
//use ajax to run the check
$.post("<?php echo base_url();?>loginFunction/checkUsername", { username: username },
function(result){
//if the result is 1
if(result == 1){
//show that the username is available
$('#username_availability_result').html(username + ' is Available');
$('#username_availability_result').css({
'color': 'black'
});
}else{
//show that the username is NOT available
$('#username_availability_result').html(username + ' is already exist. Please try another one');
$('#username_availability_result').css({
'color': 'red'
});
}
});