2011-05-02 154 views
0

我正在使用Jquery UI對話框作爲刪除記錄時的確認。我試圖實現的是,當你點擊一個提交按鈕的值爲「刪除」時,它將打開對話窗口並確認你的選擇。如果您選擇是,它將提交表單提交按鈕的值。據我所知,它現在不會工作,因爲submit()無法知道哪個按鈕被點擊了,但我不知道該怎麼去做。提前謝謝了。添加提交按鈕值提交()

<script type="text/javascript"> 
$(document).ready(function(){ 
    $("#dialog").dialog({ 
     modal: true, 
      bgiframe: true, 
      width: 500, 
      height: 200, 
     autoOpen: false 
     }); 

    $("#rusure").click(function(e) { 
     e.preventDefault(); 
     $("#dialog").dialog('option', 'buttons', { 
       "Confirm" : function() { 
        $("#tasks").submit(); 
        }, 
       "Cancel" : function() { 
        $(this).dialog("close"); 
        } 
       }); 
     $("#dialog").dialog("open"); 
    }); 
}); 
</script> 
<input type="submit" name="action" value="Delete" id="rusure"/> 

表單被稱爲「任務」,包含對話框內容的隱藏的div被稱爲「對話框」。目前,除了使用提交按鈕的值提交的表單之外,一切工作正常。表單中還有2個提交按鈕。

回答

1

試試這個:

$("#rusure").click(function(e) { 

    e.preventDefault(); 

    // Create hidden input from button and append to form 
    var input = $('<input name="confirm_delete" value="yesplz" type="hidden" />').appendTo('#tasks'); 

    $("#dialog").dialog('option', 'buttons', { 
      "Confirm" : function() { 
       $("#tasks").submit(); 
       }, 
      "Cancel" : function() { 
       $(this).dialog("close"); 
       $(input).remove();// Remove hidden input 
       } 
      }); 

    $("#dialog").dialog("open"); 

}); 

演示在這裏:http://jsfiddle.net/Madmartigan/ZGLNc/1/

+0

的伎倆感謝那確實! – David 2011-05-02 18:18:46