具有多种形式的基本 jQuery pop
我正在尝试创建一个对话框弹出框,其中包含 2 个表单。弹出窗口效果很好,但在对话框内部我有 2 个表单,每个表单都有单独的操作。
我正在使用 jQuery 表单插件来提交我的表单并显示对 #showResponse 的响应
我遇到的问题是每当我单击任一表单时,它都会加载 #showResponse 中的第一个表单,而且我不太确定为什么......
这是我的 Javascript 代码
$(".formFill2").validate({
submitHandler: function (form) {
$(form).ajaxSubmit({
target: "#submitResponse",
success: function (responseText, statusText, xhr, form) {
$("#submitResponse").show('slow');
$('#submitResponse').delay(4000).fadeOut('slow');
},
error: function (responseText, statusText, xhr, form) {
alert("Oops... Looks like there has been a problem.");
}
});
return false;
}
});
,这是我的对话框窗口中的 HTML。
<fieldset><legend>Email this PDF to</legend>
<form class="formFill2" name="emailPDF" id="emailPDF" action="classes/class.Post.php?a=notifyForm" method="post">
<label for="email1">Email 1</label>
<input name="email1" type="text" value="<?php echo $_SESSION['myEmail']; ?>"><br />
<input type="submit" value="Send Emails">
</form>
</fieldset>
<fieldset><legend>Fax this PDF to</legend>
<form class="formFill2" name="faxPDF" id="faxPDF" action="classes/class.Post.php?a=faxFile" method="post">
<label for="faxNumber">Fax #</label>
<input name="faxNumber" type="text" ><br />
<input type="submit" value="Send Fax">
</form>
</fieldset>
任何帮助将不胜感激。
I am trying to create a dialog pop-up box with 2 forms inside of it. The pop-up works great, but inside of the dialog I have 2 forms, each with separate actions.
I am using the jQuery Form Plugin, to submit my form and show a response to #showResponse
The problem i'm having is whenever I click either of the forms it loads the first form in the #showResponse, and i'm not exactly sure why....
This is my Javascript Code
$(".formFill2").validate({
submitHandler: function (form) {
$(form).ajaxSubmit({
target: "#submitResponse",
success: function (responseText, statusText, xhr, form) {
$("#submitResponse").show('slow');
$('#submitResponse').delay(4000).fadeOut('slow');
},
error: function (responseText, statusText, xhr, form) {
alert("Oops... Looks like there has been a problem.");
}
});
return false;
}
});
And this is my HTML inside my Dialog Window.
<fieldset><legend>Email this PDF to</legend>
<form class="formFill2" name="emailPDF" id="emailPDF" action="classes/class.Post.php?a=notifyForm" method="post">
<label for="email1">Email 1</label>
<input name="email1" type="text" value="<?php echo $_SESSION['myEmail']; ?>"><br />
<input type="submit" value="Send Emails">
</form>
</fieldset>
<fieldset><legend>Fax this PDF to</legend>
<form class="formFill2" name="faxPDF" id="faxPDF" action="classes/class.Post.php?a=faxFile" method="post">
<label for="faxNumber">Fax #</label>
<input name="faxNumber" type="text" ><br />
<input type="submit" value="Send Fax">
</form>
</fieldset>
Any help would be appreciative.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在这里推测了一下,但这可能是表单验证器中的一个错误。
验证插件可能会使用原始 CSS 选择器 (
.formFill2
) 来获取 SubmitHandler 函数的参数。如果他们使用get(0)
之类的东西,那么它将始终返回.formFill2
发现的第一个 DOM 对象——第一个表单。如果您
console.log
传递到submitHandler
中的“form”参数,您是否会获得正确的表单?如果它总是给您第一个表单,您可能需要尝试如下操作:
I'm speculating a bit here, but it might be a bug in the form validator.
It may be the case that the Validate plugin is using your original CSS selector (
.formFill2
) in order to get the parameter for the submitHandler function. If they're using something likeget(0)
, then it'll always return the first DOM object discovered by.formFill2
-- the first form.If you
console.log
the 'form' parameter that is passed into yoursubmitHandler
, do you get the right form?If it's always giving you the first form, you might want to try something like the following: