& # 39;成功# 39;jquery表单验证后的对话框清除并提交-无论如何都显示成功消息
'success' dialog after jquery form validation clears and submits - showing success message no matter what
我有一个简单的电子邮件表单:
<form method="post" action="process-form.php" id="emailForm" name="emailForm" target="_self">
<h4>Sign up to be notified when we go live!</h4>
<label for="email">E-mail</label>
<input type="text" name="email" id="email" />
<input type="submit" name="submit" id="submit" value="Submit" onclick="return alert('Thanks! Your email has been added.');">
<p>emails will not be shared with third parties</p>
</form>
我使用以下jQuery验证:
/*
Created 09/27/09
Questions/Comments: jorenrapini@gmail.com
COPYRIGHT NOTICE
Copyright 2009 Joren Rapini
*/
$(document).ready(function(){
// Place ID's of all required fields here.
required = ["email"];
// If using an ID other than #email or #error then replace it here
email = $("#email");
errornotice = $("#error");
// The text to show up within a field when it is incorrect
emptyerror = "Please fill out this field.";
emailerror = "Please enter a valid e-mail.";
$("#emailForm").submit(function(){
//Validate required fields
for (i=0;i<required.length;i++) {
var input = $('#'+required[i]);
if ((input.val() == "") || (input.val() == emptyerror)) {
input.addClass("needsfilled");
input.val(emptyerror);
errornotice.fadeIn(750);
} else {
input.removeClass("needsfilled");
}
}
// Validate the e-mail.
if (!/^([a-zA-Z0-9_'.'-])+'@(([a-zA-Z0-9'-])+'.)+([a-zA-Z0-9]{2,4})+$/.test(email.val())) {
email.addClass("needsfilled");
email.val(emailerror);
}
//if any inputs on the page have the class 'needsfilled' the form will not submit
if ($(":input").hasClass("needsfilled")) {
return false;
} else {
errornotice.hide();
return true;
}
});
// Clears any fields in the form when the user clicks on them
$(":input").focus(function(){
if ($(this).hasClass("needsfilled") ) {
$(this).val("");
$(this).removeClass("needsfilled");
}
});
});
表单验证成功后,我希望显示一个成功对话框。我现在在提交按钮的onClick
事件中有这个,但显然不管它是否验证,它都会显示消息。我认为消息需要放在验证的某个地方
在onsubmit函数的最后,返回'true'
相关文章:
- jQuery Ajax成功提交条件问题
- 使用GET方法通过AJAX成功提交表单后更改url
- Jquery 提交表单,在成功提交表单到 php 后添加
- 在JSP中成功提交表单后清除表单字段
- 如何在成功提交后关闭弹出表单
- 仅当表单成功提交时才发生jQuery事件
- 成功提交 Web 表单后,Javascript 重置功能将不起作用
- 如何在以下代码中在 AngularJS 中成功提交后清空(或重置)表单上的所有输入字段
- 成功提交时显示引导程序的警报
- 如何做不成功提交表单jquery
- 成功提交表单后重定向用户
- 成功提交表单后显示元素
- 如何在成功提交后关闭模态框,并在表单提交时有条件地打开第二个模态
- jQuery Validator无效输入字段在成功提交后消失
- 如何在成功提交表单后重新加载导航栏
- 仅在成功提交时删除输入掩码
- 如何在成功提交表单时推送dataLayer事件?(使用Ninja Forms WP Plugin)
- 错误或成功提交表单时的警报消息
- 如何重新启用ajax成功提交按钮
- 成功提交后获得表单弹出