每当我尝试提交表单时,我都会收到错误,或者如果我在控制台中手动输入,则会收到以下错误:
RangeError: Maximum call stack size exceeded
这是我的代码:
$(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();
}
})
});