2010-05-29 64 views
0

我想在提交表单之前显示jquery的对话框确认。但我不能让它弹出了只有当表单提交这是代码: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()"> 

回答

1

功能remove不应放置在$(...);中,因为$(function(){})是在文档加载时自动执行的东西,只需将该函数移动到b e明确定义在根上。另外我会建议使用内联回调;设置形式和使用上的id以下代替:

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 
})