console
$('#verification').hide();
$('#login').click(function () {
if ($(":text").val().length == 0) {
$('#username').focus();
$("#errorMessage").html(
"请您填写手机/邮箱/用户名").css("color","red");
} else if ($(":password").val().length == 0) {
$('#password').focus();
$("#errorMessage").html(
"请您填写密码").css("color","red");
$('#verification').show();
} else if ($('#verification').val().length == 0) {
$('#verification').focus();
$('#errorMessage').html("请您填写验证码").css("color","red");
}
});
$('#verification').blur(function () {
if ($('#username').val().length != 0 && $('#password').val().length != 0) {
if ($('#verification').val().length == 0) {
$('#errorMessage').html("请您填写验证码").css("color","red");
} else if ($('#verification').val() != 'yzm') {
$("#errorMessage").html(
"您输入的验证码有误: " + $('#verification').val()).css("color","red");
} else {
$("#errorMessage").html('').css("color","red");
}
}
});
<p id="errormessage"></p>
<input id="username" type="text" name="username"><br>
<input id="password" type="password" name="password"><br>
<input type="text" id="verification"/><br>
<button id="login">登录</button>