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