Chrome 未捕获的语法错误:意外的令牌非法
2022-08-30 04:12:05
当 Chrome 尝试在网页上加载脚本文件时收到主题错误。它说它位于javascript文件的最后一行。我似乎找不到任何错误。firefox 中没有错误,脚本按预期工作。仅使用表单验证
// JavaScript Document
$(function() {
$('#wm-form').submit(function() {
var errors = false;
var errorMsg = "";
$('.required').each(function() {
if(!validField($(this))) {
errorMsg += $(this).attr('name').capitalize() + " cannot be blank\n";
errors = true;
}
});
var emailAddress = $('#email');
if(isValid(emailAddress) && !(/^(([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5}){1,25})+([;.](([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5}){1,25})+)*$/.test(emailAddress.val()))) {
errorMsg += "Not a valid email address. Please enter in a correctly formatted email address";
errors = true;
}
if(errors) {
alert(errorMsg);
return false;
}
});
$('.form-focus').click(function() {
$(document).scrollTop(0);
$('#first_name').focus();
return false;
});
});
function validField(element) {
if(!isValid(element.val()) || (element.attr('placeholder') && element.attr('placeholder') == element.val()) ||
(element.attr('type') == 'radio' && !checkedRadio(element))) {
return false;
}
else {
return true;
}
}
function isValid(ele) {
if(ele == null || ele == '') {
return false;
}
else {
return true;
}
}
String.prototype.capitalize = function() {
return this.charAt(0).toUpperCase() + this.slice(1);
};
function checkedRadio (element) {
var valid = false;
$('input[name="'+ element.attr("name") +'"]:checked').each(function() {
valid = true;
});
return valid;
}