2014-03-27 25 views
-1

我有一個表單,我正在建設 - 完全一樣的任何其他形式。但是,一如既往,有一個錯誤:jQuery「意外的標識符」與阿賈克斯形式檢查

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 { } 
       } 
      }); 
     } 
    }); 
}); 

回答

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

一直缺少一個)。所以它應該是

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

我不知道爲什麼沒有出現在Dreamweaver中的錯誤它通常用PHP做。 –

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