尝试使用Jquery验证我的登录表单,当错误评估为true时,错误应该向下滑动,呈现相应的文本,但不会。我已经设法在所有其他形式上进行此项工作,但由于某种原因,它不喜欢此登录表单。验证登录表单; Jquery
CSS代码
.error{
color: red;
padding: 2px;
text-align: left;
margin-left: 100px;
margin-top: 50px;
display: none;
height: 70px;
width: 400px;
float: left;
}
登录形式
<form id="login_form" method="post" action="login.php">
<fieldset><legend>Login</legend>
<label for="email">Email</label>
<input type="text" name="email" id="email" />
<br/>
<label for="password">Password</label>
<input type="password" name="password" id="password" />
<br/>
<input type="submit" name="submit" value="login" />
</fieldset>
</form>
jQuery代码
$('#submit').click(function(){
$('.error').slideDown("slow");
});
//Log In Validation
$('#login_form').submit(function(e){
// initialize error
var error = false;
$('.error').empty();
if ($('#email').val() == "") {
$('.error').append("<li>Please enter your email address</li>");
error = true;
}
if ($('#password').val() == "") {
$('.error').append("<li>Please enter a password<li>");
error = true;
}
if (error) {
e.preventDefault();
}
});
究竟是不是工作,因为我不能找到'.error'在你的HTML? – Phil
您的调试控制台是否会抛出任何错误? – David
Slidedown功能。对不起,应该解释。 – user1829823