2010-05-29 78 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 
})