【问题标题】:jquery ui-dialog form submiting not workjquery ui-dialog表单提交不起作用
【发布时间】:2014-11-22 12:17:23
【问题描述】:
var currentForm;
$("#confirm").dialog({
    autoOpen: false,
    title: "First we must ask you!",
    resizable: false,
    width:500,
    height:190,
    modal: true,
    buttons: {
        'Submit for God sake!': function() {
            currentForm.submit();
        },
        Cancel: function() {
            $(this).dialog('close');
        }
    }       
});
$('.clientForm').submit(function(e){
    currentForm = $(this);
    $('#confirm').dialog('open');
    return false;
});

你好。

我有一个必须在确认后才能提交的表格。要执行此操作,我使用 ui-dialog 方法。问题是在 ui-dialog 出现后表单不想提交,访问者必须点击确认按钮。

当我查看代码时,一切似乎都是正确的。

这里是JSFiddle的链接

【问题讨论】:

    标签: jquery forms user-interface submit


    【解决方案1】:

    由于表单提交事件中的这一行return false;,它没有发布。这导致表单无法发布。

    $('.clientForm').submit(function(e){
            currentForm = $(this);
            $('#confirm').dialog('open');
            return false; // this line will always stop your form from posting
        });
    

    给出提交按钮的id并写下它的点击事件:

     <button id="go" type="submit">Go there</button>
    

    jquery 事件:

    $('#go').click(function(e){
            currentForm = $(this).closest("form");
            $('#confirm').dialog('open');
            return false;
        });
    

    FIDDLE DEMO

    另一种选择是使按钮类型为button 而不是submit 这不会导致您的表单在点击时提交:

    <button id="go" type="button">Go there</button>
    

    和jquery:

    $('#go').click(function(e){
            currentForm = $(this).closest("form");
            $('#confirm').dialog('open'); // no need to return false as button type is not submit
        });
    

    DEMO

    【讨论】:

    • 感谢您的回答。所以你想说在这种情况下解决方案不存在?毕竟,如果我删除 return false ui-dialog 会出现,但表单不会暂停自己的提交。有什么办法可以暂停,而不是停止提交?
    • 查看我更新的答案,你必须给按钮 id 写它的点击事件才能停止提交。
    • 谢谢。现在表单真的提交了。
    【解决方案2】:

    除了$('.clientForm').submit(function(e){,一切都正确。

    $('.clientForm').submit(function(e){ 替换为$('.clientForm').click(function(e){。这应该可以。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-20
      相关资源
      最近更新 更多