您可以使用.css()
設置背景顏色,請參見下面的代碼
function checkPasswordMatch() {
var password = $("#textpwd").val();
var confirmPassword = $("#textcfmpwd").val();
if (password != confirmPassword)
{
$("#pwdWarning").html("Passwords do not match!");
$("#pwdWarning").css('background-color','red');
}
else
{
$("#pwdWarning").html("Passwords match.");
$("#pwdWarning").css('background-color','green');
}
}
DEMO
或者您也可以使用CSS類新添加背景顏色,請參見下面的代碼
CSS
.red{background-color:red;}
.green{background-color:green;}
jQuery的
function checkPasswordMatch() {
var password = $("#textpwd").val();
var confirmPassword = $("#textcfmpwd").val();
if (password != confirmPassword)
{
$("#pwdWarning").html("Passwords do not match!");
$("#pwdWarning").addClass('red').removeClass('green');
}
else
{
$("#pwdWarning").html("Passwords match.");
$("#pwdWarning").addClass('green').removeClass('red');
}
}
DEMO
CSS是很好的地方開始 – ethorn10 2014-11-05 04:49:49
你爲什麼不'谷歌jQuery的css' – 2014-11-05 04:54:59