多页jQuery表单没有提交

时间:2014-02-24 13:04:11

标签: javascript jquery forms

这是jQuery代码

$("#register-form").submit(function (e) {
    e.preventDefault();
}).validate({
    rules: {
        name: "required",
        address: "required",
        phone: "required",
        landmark: "required",
        pincode: "required",
        city: "required",
        email: {
            required: true,
            email: true
        }
    },
    messages: {
        name: "Please enter your name",
        address: "Please enter your address",
        phone: "Please enter your phone",
        landmark: "Please enter your landmark",
        pincode: "Please enter your pincode",
        city: "Please enter your city",
        email: "Please enter a valid email address"
    },
    submitHandler: function (form) {
        //form.submit();
        //alert("Do some stuff...");
        $("#step1").hide();
        //$('#step1img').css('opacity','0.5');
        //$('#step2img').css('opacity','1');
        $("#step2").show();

        //submit via ajax
        return false;
    }
});
// });

$("#back").click(function () {
    $("#step1").show();
    $("#step2").hide();
});

function submitform() {
    document.getElementById('#register-form').submit();
}

这是我的小提琴,http://jsfiddle.net/bd4T2/我尝试了多页形式,使用jquery验证js,但表单没有提交

1 个答案:

答案 0 :(得分:0)

好吧,我把代码复制出了小提琴(它没有工作,也没有包含jquery库),我在submitform函数中发现了错误,你在表单id前面有一个哈希值使用dom找到表格:

function submitform() {
    document.getElementById('#register-form').submit(); //<-- '#register-form'
}
//this is not going to work, you were looking to use jquery here
document.getElementById('#register-form').submit();

不起作用,因为表单ID中没有#,所以它应该是这样的;

function submitform() {
   $('#register-form').submit();
}