我有一个正在构建的表单 - 与任何其他表单完全相同。但是,和往常一样,有一个错误:
Uncaught SyntaxError: Unexpected identifier
以下是错误引用的脚本部分:
alert( $('#email_err').html() );
if ( checkEmail( $('#email').val() ) {
$('#email_err').html(''); //the error refers to this line
} else {
$('#email_err').html('That email address appears to be invalid');
count++;
}
所以我的问题是alert( $('#email_err').html() );
和$('#email_err').html('');
之间有什么区别?他们显然是一样的。可能有一些我忽略的东西,但我的形式的其余部分完全使用相同的方法。
如果它有助于继承全部功能:
$(document).ready(function (e) {
$('#reg').on('submit', function (e) {
var count = 0;
e.preventDefault();
alert( $('#email_err').html() );
if ( checkEmail( $('#email').val() ) {
$('#email_err').html('');
} else {
$('#email_err').html('That email address appears to be invalid');
count++;
}
if ( $('#pass').val() === $('#c_pass').val() ) {
$('#c_pass_err').html('');
} else {
count++;
$('#c_pass_err').html('Your password don\'t appear to match, please try again.');
}
if ( count === 0 ) {
var fd = new FormData($('#reg')[0]);
$.ajax({
url:'<?php echo $dir; ?>global.func/register.php',
type:'POST',
dataType:'JSON',
processData: false,
contentType: false,
data:fd,
success: function( json ) {
if ( parseInt(json.err) === 1 ) {
$('#reg_err').html(json.err_msg);
} else { }
}
});
}
});
});
答案 0 :(得分:6)
if( checkEmail( $('#email').val() )
缺少)
。所以它应该是
if( checkEmail( $('#email').val() ) )
答案 1 :(得分:0)
你在checkEmail之后忘了“)”(... 它应该是:
alert($('#email_err').html());
if(checkEmail($('#email').val())){
$('#email_err').html(''); //the error refers to this line
}else{
$('#email_err').html('That email address appears to be invalid');
count++;
}