模态确认 - 如果单击确定,则表单未提交

时间:2012-09-11 22:24:46

标签: jquery modal-dialog

我在页面上有多个表单(自动生成)。我要求用户确认删除记录。如果用户单击否,则关闭模态对话框并且没有任何反应,但是如果他单击是按钮,则不会再发生任何事情。有人可以帮忙吗?

以下是代码:

 <input type="submit" value="Click me" class="button" />

 <div id="modal">
<div id="heading">
    Record will be deleted! Please Confirm.
</div>

<div id="content">
    <p>Record will be deleted! This operation can't be undone. <br />Are you sure?</p>

    <input type="button" onclick="return true;" class="button green close" value="Yes"></button>
    <input type="button" onclick="return false;" class="button red close" value="No"></button>

</div>

$('.oneUser').on('submit',function(e){
    $('#modal').reveal({ 
        animation: 'fade',                   
        animationspeed: 600,                       
        closeonbackgroundclick: true,           
        dismissmodalclass: 'close'    
    });
    return false;
});

1 个答案:

答案 0 :(得分:1)

已更新,现在有A fiddle!

更新了标记

<form>
    <input type="submit" value="Click me" class="button" id="submitButton" />
</form>​
  • 删除了对话框标记。
  • 包含的表单标记。

更新了脚本

var confirmDelete = $('<div></div>')
    .html('Record will be deleted! This operation can\'t be undone. <br />Are you sure?')
    .dialog({
        autoOpen: false,
        title: 'Record will be deleted! Please Confirm.',
        buttons: {"Yes": function() { 
                      $(this).dialog("close"); 
                      $('form').submit();
                 }, "No": function() {
                      $(this).dialog("close");
                 }
        }
    });  
$('#submitButton').on('click', function(e){
    e.preventDefault();
    $(confirmDelete).dialog('open');
});
  • 使用按钮的点击事件而不是表单的提交事件。
  • 实施对话框like this guy did it
  • 是,没有选项会关闭对话框,点击“是”也会调用$('form').submit();