<script>
$("#myform").submit(function(){
// Assume there are no error on the form
var errors = false;
// Hide all the error messages
$(".error").hide();
// Check each field to make sure they're not blank
if($("#first").val() == ""){
$("#first_error").show();
errors = true;
}
if($("#last").val() == ""){
$("#last_error").show();
errors = true;
}
if($("#un").val() == ""){
$("#un_error").show();
errors = true;
}
if($("#pass").val() == ""){
$("#pass_error").show();
errors = true;
}
// If there are errors, then show a general error message
if(errors){
$("span".text("Oops, ya missed something, try again.").show().faeOut(5000);
return false;
}
// If there are not any errors, show a success message
$(".success").fadeIn();
return true;
});
// Make the close button on the success screen work
$(".close).click(function(){
$(".success").fadeOut();
});
</script>
答案 0 :(得分:2)
你的牙套没有得到适当的平衡。您错过了此if
块的右大括号:
if(errors){
$("span".text("Oops, ya missed something, try again.").show().faeOut(5000);
return false;
}
// If there are not any errors, show a success message
$(".success").fadeIn();
return true;
}
});
你在这里错过了一句话:
$(".close").click(function(){
^
此外,所有代码都应该在$(document).ready()
函数内。
答案 1 :(得分:-2)
$(document).ready(function(){
//your code
});
也许你错过了document.ready()