无法使submit()工作

use*_*717 4 jquery

当我尝试提交表单时,我得到一个错误,或者如果我在我的控制台中手动输入它,我会收到此错误:

RangeError: Maximum call stack size exceeded
Run Code Online (Sandbox Code Playgroud)

这是我的代码:

$(document).ready(function() {
    $('#contact').on('submit', function(event) {
        event.preventDefault();
        var valid = 1;
        var name = $('input[name$="name"]');
        var email = $('input[name$="email"]')
        var phone = $('input[name$="phone"]');
        var comment = $('input[name$="comment"]');
        if (!name.val() && valid == 1) {
            valid = 0;
            alert('Please fill out the Name field');
            name.focus();
        }
        if (!email.val() && valid == 1) {
            valid = 0;
            alert('Please fill out the E-mail Address field');
            email.focus();
        }
        if (!phone.val() && valid == 1) {
            valid = 0;
            alert('Please fill out the Phone field');
            phone.focus();
        }
        if (valid == 1) {
            $('#contact').submit();
        }
    })
});
Run Code Online (Sandbox Code Playgroud)

Nog*_*ter 17

您正在从提交处理程序调用提交,因此它是无限递归.true如果有效,您想要返回false.

编辑:哦,我不确定你想在这种情况下阻止默认.