0
出於某種原因,我的jQuery驗證和ajax將無法正常工作,我看不到我在哪裏做了這個腳本錯誤。我在頭文件中引用jquery,當我刪除ajax函數時腳本運行正常。任何人都可以看到發生了什麼?jquery驗證將不會執行
<script type="text/JavaScript">
$(document).ready(function() {
$('#btn-submit').click(function(e) {
// stop normal button action, whatever it is
e.preventDefault();
$(".error").hide();
var hasError = false;
var emailReg = /^([\w-\.][email protected]([\w-]+\.)+[\w-]{2,4})?$/;
var emailaddressVal = $("#UserEmail").val();
if(emailaddressVal == '') {
$("#submit").after('<span class="error">Please enter a email address.</span>');
hasError = true;
}
else if(!emailReg.test(emailaddressVal)) {
$("#submit").after('<span class="error">Email Not Valid');
hasError = true;
} else if(emailReg.test(emailaddressVal)){
$("#submit").after('<span class="error">Email Updated');
}
if (!hasError) {
$.ajax({
type: "POST",
url: "updateEmails.php",
data: "UserEmail="+emailaddressVal,
success: function(data){
$(".parentEmail").html(emailaddressVal);
}
});
}
});
});
</script>
<form method="post" name="form1" action="">
<label>Email Address:</label>
<input type="text" name="UserEmail" id="UserEmail" value="" size="32" />
<input type="submit" value="Submit" id="btn-submit" />
</form>
要插入的格式不正確的HTML幾個'.after()'調用。您錯過了結束範圍標籤。 – 2011-06-09 06:23:17