在提交表格之前,我正在尝试显示jQuery的对话框确认。但是我不能仅在提交表单时才能弹出它,这是代码:

$(function remove() {                           
    $("#dialog-confirm").dialog({
        resizable: false,
        height:200,
        modal: true,
        buttons: {
            'Delete campaign': function() {
                return true ;
                $(this).dialog('close');
            },
            Cancel: function() {
                return false;
                $(this).dialog('close');
            }
        }
    });
});

对话确认内容

  <div id="dialog-confirm" title="Delete ?" style="display:none;">
    <p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>This will be permanently deleted and cannot be recovered. Are you sure?</p>
</div>

表格提交内容

<form style="display: inline;" action="remove.php" method="post"" onsubmit="return remove()">
有帮助吗?

解决方案

功能 remove 不应该放在 $(...);, , 作为 $(function(){}) 是在加载文档时会自动执行的内容,只需移动要清楚地定义的函数即可。我也建议使用内联回调;设置一个 id 在表单上并使用以下方式:

IE

function remove() {
  ...
}
$(function(){
  $('#formid').submit(remove);
  // normal initializing code here, which is executed when document is ready
})

或者,您也可以直接定义回调:

$(function(){
  $('#formid').submit(function(){
    // same code as in remove function above
  });
  // normal initializing code here, which is executed when document is ready
})   
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top