我尝试制作 Ajax 表单并尝试在那里进行电子邮件验证。我找到了这个解决方案 http://jsfiddle.net/EFfCa/
但无法在我的脚本中打开它:
<script>
$('#joinForm').ajaxForm(function() {
var testEmail = /^[A-Z0-9._%+-]+@([A-Z0-9-]+\.)+[A-Z]{2,4}$/i;
var name = $("input[name=name]")
var email = $("input[name=email]")
if(name.val()==''||email.val()=='') {
$(".notify").show();
$(".notify p").text('empty');
} else if(testEmail.test(email.value)) {
$(".notify").show();
$(".notify p").text('email is wrong');
} else {
$(".notify").show();
$(".notify p").text('good');
}
});
</script>
即使电子邮件错误,表格也始终通过验证。对空字段的验证效果很好...