jQuery"意外的标识符“;使用ajax表单检查

jQuery "Unexpected identifier" with ajax form checks

本文关键字:ajax 使用 表单 检查 quot 意外 jQuery 标识符      更新时间:2023-09-26

我有一个正在构建的表单-与任何其他表单完全相同。但是,一如既往,有一个错误:

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 { }
                }
            });
        }
    });
});
if( checkEmail( $('#email').val() )

缺少一个)。所以应该是

if( checkEmail( $('#email').val() ) )

检查后忘记了"("电子邮件(。。。应该是:

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++;
}