带有嵌套表单的 Jquery 对话框有提交问题
我有一个带有嵌套表单的 jquery 对话框,如下所示:
<!-- Store Location Dialog -->
<div id = "changeDialog">
<form id = "form" method = "post" action = "Default.aspx" \>
<input type = "text" id = "changeText" name = "changeLocation" />
<input type = "button" id = "changeStoreDialogSubmit" value = "" onclick = "dialogSubmitForm()"/>
</form>
</div>
单击按钮时可能会发生两种情况。一个实例需要加载页面,而另一个则不需要。我的非页面加载实例工作正常,但另一个则不能。这是我拥有的 dialogSubmitForm()
方法:
function dialogSubmitForm() {
if (!placeHolderVisibility) {
$('#changeStoreDialogSubmit').submit();
}
else /
{
//Working code
}
}
这是对话框:
function createDialog() {
//Creates a new dialog
$('#changeDialog').dialog({
resizable: false,
title: '<span class="ui-icon ui-icon-home"></span> Enter Info',
});
}
当我测试页面时,我可以看到 $('#changeStoreDialogSubmit').submit();
受到攻击,但页面从未加载。为什么会出现这种情况呢?
I have a jquery dialog with a nested form like this:
<!-- Store Location Dialog -->
<div id = "changeDialog">
<form id = "form" method = "post" action = "Default.aspx" \>
<input type = "text" id = "changeText" name = "changeLocation" />
<input type = "button" id = "changeStoreDialogSubmit" value = "" onclick = "dialogSubmitForm()"/>
</form>
</div>
There are two instances that could happen when the button is clicked. One instance will require a page load, and the other will not. I have the non-page load instance working correctly, but the other one is not. Here is the dialogSubmitForm()
method I have:
function dialogSubmitForm() {
if (!placeHolderVisibility) {
$('#changeStoreDialogSubmit').submit();
}
else /
{
//Working code
}
}
And here is the dialog:
function createDialog() {
//Creates a new dialog
$('#changeDialog').dialog({
resizable: false,
title: '<span class="ui-icon ui-icon-home"></span> Enter Info',
});
}
When I test the page I can see the $('#changeStoreDialogSubmit').submit();
getting hit, but there is never a page load. Why would this happen?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要在
form
上调用.submit()
,而不是提交表单的按钮:You need to call
.submit()
on theform
, not the button that submits the form:submit()
方法只能在form
元素上调用。您的表单的 ID 为form
,因此您需要将其更改为:话虽这么
说,我认为您正在为您的应用程序使用 ASP.NET,并且您确实需要确保不要有嵌套的
form
标记,因为默认情况下 Web 表单会在您的页面上抛出一个form
标记。The
submit()
method can only be invoked onform
elements. Your form has an ID ofform
, so you need to change this:To this:
That being said, I gather that you are using ASP.NET for your application, and you really need to make sure you do NOT have nested
form
tag, because Web Forms by default will throw aform
tag on your page for you.