带有嵌套表单的 Jquery 对话框有提交问题

发布于 2024-11-02 17:01:48 字数 1125 浏览 1 评论 0原文

我有一个带有嵌套表单的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

荒岛晴空 2024-11-09 17:01:48

您需要在 form 上调用 .submit(),而不是提交表单的按钮:

function dialogSubmitForm() {

    if (!placeHolderVisibility) {

        $('#form').submit();
    }
    else 
    {
        //Working code
    }
}

You need to call .submit() on the form, not the button that submits the form:

function dialogSubmitForm() {

    if (!placeHolderVisibility) {

        $('#form').submit();
    }
    else 
    {
        //Working code
    }
}
骑趴 2024-11-09 17:01:48

submit() 方法只能在 form 元素上调用。您的表单的 ID 为 form,因此您需要将其更改为:

$('#changeStoreDialogSubmit').submit();

话虽这么

$('#form').submit();

说,我认为您正在为您的应用程序使用 ASP.NET,并且您确实需要确保不要有嵌套的 form 标记,因为默认情况下 Web 表单会在您的页面上抛出一个 form 标记。

The submit() method can only be invoked on form elements. Your form has an ID of form, so you need to change this:

$('#changeStoreDialogSubmit').submit();

To this:

$('#form').submit();

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 a form tag on your page for you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文