如何在表单有效且正确提交之前确保窗口没有关闭? 因为现在它关闭弹出窗口并且nobady知道表单是否有效。因为即使有错误,表格也会立即关闭。
$(document).ready(function(){
$(".requestPassword").hide();
$(".popupwindow").popupwindow(profiles);
$(".fp").click(function(){
$(".loginForm").hide();
$(".requestPassword").show();
});
$(".back").click(function(){
$(".loginForm").show();
$(".requestPassword").hide();
});
//form validation
$("#aanmeldForm").validate({
//set the rules for the field names
rules: {
firstname: {
required: true,
minlength: 2
},
email: {
required: true,
email: true
},
message: {
required: true,
minlength: 2
},
},
//set messages to appear inline
messages: {
name: "Please enter your name",
email: "Please enter a valid email address"
},
errorPlacement: function(error, element) {
error.appendTo( element.parent("td"));
}
});
$("#aanmeldForm").submit(function(){
//TODO: some data keeping jobs to be done
self.opener.location = 'http://ladosa.com';
self.close();
});
});
答案 0 :(得分:2)
检查表单是否有效,如果不是,则返回false;提交之外:
$("#aanmeldForm").submit(function(){
//TODO: some data keeping jobs to be done
// make sure the form was valid *before* dismissing the popup
if($(this).valid()) {
self.opener.location = 'http://ladosa.com';
self.close();
return true;
}
// stop the form submitting
return false;
});