在JavaScript中更改字体颜色

时间:2018-07-31 06:52:15

标签: javascript php codeigniter

这是我的JavaScript代码:

if (password != confirmPassword)
        $("#divCheckPasswordMatch").html("Passwords do not match!");
    else
        $("#divCheckPasswordMatch").html("Passwords match.");
}

我只想将“密码不匹配”消息的颜色更改为红色。 我是初学者,有人可以帮我吗?

5 个答案:

答案 0 :(得分:1)

尝试使用:

password = '123x';
confirmPassword = '123';
if (password != confirmPassword) {
  $("#divCheckPasswordMatch").html("Passwords do not match!").css('color', '#900');

} else {
  $("#divCheckPasswordMatch").html("Passwords match.").css('color', '#090');
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="divCheckPasswordMatch"></div>

答案 1 :(得分:1)

def get(self, filename):
    # RETURN THE INVOICE
    file_name = str(expanduser("~")) + UPLOAD_PATH + str(filename)
    f = open(file_name, "rb")
    output = f.read()
    self.set_header('Content-Disposition', 'attachment; filename=output.csv')
    self.set_header('Content-type', 'text/csv')
    self.write(output)
    print("Invoice download")

$("#divCheckPasswordMatch").html("Passwords do not match!");

答案 2 :(得分:0)

if (password != confirmPassword){
        $("#divCheckPasswordMatch").html("<span style='color:red'>Passwords do not match!</span>");
 }   else {
        $("#divCheckPasswordMatch").html("Passwords match.");
}

答案 3 :(得分:0)

$("#divCheckPasswordMatch").css('color', 'red');

在您的1.if ^^

答案 4 :(得分:0)

您可以使用css()方法:

if (password != confirmPassword)
{
    $("#divCheckPasswordMatch").html("Passwords do not match!");
    $("#divCheckPasswordMatch").css('color', 'red');
} else {
    $("#divCheckPasswordMatch").html("Passwords match.");
    $("#divCheckPasswordMatch").css('color', 'green');
}

您可以在jquery .css documentation page上找到更多详细信息