如何使用 JQuery UI 提交表单?
我有一个带有默认提交按钮的 html 表单。提交表单后,将运行一个 php 文件(其中 action = homelocation)。我决定使用 JQuery UI 对话框来显示表单。我有 2 个默认按钮 - 一个用于保存,一个用于关闭对话框。谁能告诉我如何将表单提交按钮操作分配给 JQuery 对话框按钮(即用对话框中的按钮替换表单中的提交按钮)?这是我的代码:
<div id="userdialog" title="Add">
<form id="add" action="engine.php" method="POST">
<input type="hidden" name="action" value="homelocation" id="action">
<button type="submit">Save this location</button>
</form></div>
对话框:
$('#userdialog').dialog({
width: 260,
position: [250,100],
buttons: {
"Save": function() {
HERE GOES THE REQUIRED FUNCTION
$(this).dialog('close'); },
"Don't Save": function() {
$(this).dialog("close");
}
}
});
I have a form in html with a default submit button. After the form is submitted, a php file is run (with action = homelocation). I decided to use JQuery UI dialog to display the form. I have 2 default buttons there - one to save and one to close the dialog. Can anyone tell me how to assign the form submit button action to the JQuery dialog button(i.e. replace the submit button from the form with the one in the dialog)? Here's my code:
<div id="userdialog" title="Add">
<form id="add" action="engine.php" method="POST">
<input type="hidden" name="action" value="homelocation" id="action">
<button type="submit">Save this location</button>
</form></div>
Dialog:
$('#userdialog').dialog({
width: 260,
position: [250,100],
buttons: {
"Save": function() {
HERE GOES THE REQUIRED FUNCTION
$(this).dialog('close'); },
"Don't Save": function() {
$(this).dialog("close");
}
}
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以这样做:
或者,您可以调用
$("#add").submit();
显式使用 ID,上面的版本会在当前对话框中查找任何表单。You can do this:
Alternatively, you can call
$("#add").submit();
to use the ID explicitly, the version above looks inside the current dialog for any forms.