0

我有一个 Django 表单。我需要一个关于表单提交的确认/取消对话框。A 有一个从 jQuery 发送 POST 数据的想法……但它是一种使用 javascript 对话框作为中间件的方法吗?

4

1 回答 1

3

根据您的需要在 Html 中添加波纹管代码

<form><input type="submit" value="Submit" id="confirm"/> </form>

和确认对话框的 jQuery 代码

<script>
    jQuery("#confirm").click(function(){
        $("<div></div>").appendTo('body')
           .html('<div><h3> write your message for confirm dialog</h3></div>')
           .dialog({
                title: "Confotm Dialog" ,
                width:500, height:300,
                modal:true,
                resizable: false, 
                show: { effect: 'drop', direction: "left" }, 
                hide:{effect:'blind'}

                buttons: {
                    Yes: function() {
                          jQuery.ajax({
                              type:"POST", //post data
                              data:{'key':key}, //if you want to send any data to view 
                              url:'/get_viewerModal/' // your url that u write in action in form tag
                          }).done(function(result){
                               alert("am done") //this will executes after your view executed  
                          })
                     },
                    Cancel: function() {
                        $( this ).dialog( "close" );
                    }
               }
           });
    });
<script> 

在这里你需要 ajax 知识,而且它很容易使用,我相信你这样做:)

于 2013-01-24T07:30:06.367 回答