0

如何确保在表单有效并正确提交之前窗口不会关闭?因为现在它关闭了弹出窗口并且没有人知道表单是否有效。因为即使出现错误,表格也会立即关闭。

    $(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();
        });


});
4

1 回答 1

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;
});
于 2009-04-05T21:00:37.470 回答