2011-05-02 158 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