我設置我的錯誤消息在我的表單與jquery,當我去看看它並沒有要求名稱字段是必需的,但只是電子郵件,即使我已經包括它。這裏是我的代碼:AJAX驗證與jquery
<form method="post" action="" id="contactform">
<fieldset class="first">
<div id="response"></div>
<div class="name_input">
<input name="name" id="name" class="required" type="text" onfocus="if(this.value == 'Name'){this.value = '';}" onblur="if(this.value == ''){this.value='Name';}" value="Name" maxlength="128" />
</div>
<div id="email_input">
<input id="email" name="email" onfocus="if(this.value == 'Email'){this.value = '';}" onblur="if(this.value == ''){this.value='Email';}" class="required" type="text" value="Email" maxlength="128" />
</div>
<div id="button">
<input type="submit" class="button" name="Submit" value="" />
</div>
</fieldset>
</form>
和我的JS:
$(document).ready(function() {
$('form #response').hide();
$('#button').click(function(e) {
e.preventDefault();
var valid = '';
var required = ' is required.';
var name = $('form #name').val();
var email = $('form #email').val();
if (name == '' || name.length < 2) {
valid = '<p>Your name' + required +'</p>';
}
if (!email.match(/^([a-z0-9._-][email protected][a-z0-9._-]+\.[a-z]{2,4}$)/i)) {
valid += '<p>Your email' + required +'</p>';
}
if (valid != '') {
$('form #response').removeClass().addClass('error')
.html('<strong>Please correct the errors below.</strong>' +valid).fadeIn('fast');
}
else {
$('form #response').removeClass().addClass('processing').html('Processing...').fadeIn('fast');
var formData = $('form').serialize();
submitForm(formData);
}
});
});
有不有我名牌的其他任何地方的任何衝突,所以我不知道什麼是可能發生的情況
其中是您的ajax驗證碼。 – Jai