Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jquery对话框post如果为true_Javascript_Jquery_Dialog - Fatal编程技术网

Javascript jquery对话框post如果为true

Javascript jquery对话框post如果为true,javascript,jquery,dialog,Javascript,Jquery,Dialog,我有下面的代码示例,仅当用户单击Yes按钮时,我才尝试发出post请求。如果用户单击“否”按钮,则不会发生任何事情。谢谢你的帮助和提示 <html> <head> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <link href="https://ajax.googleapis.com/aja

我有下面的代码示例,仅当用户单击Yes按钮时,我才尝试发出post请求。如果用户单击“否”按钮,则不会发生任何事情。谢谢你的帮助和提示

<html>
<head>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <link href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css"
        rel="stylesheet" />
    <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
</head>
<body>
    <form action="" method="post">
        <button id="save" onclick="return ConfirmDialog('this is a test')">Save</button>
    </form>

<script>
    function ConfirmDialog(message) {
        $('<div></div>').appendTo('body')
            .html('<div><h6>' + message + '?</h6></div>')
            .dialog({
                modal: true,
                title: 'Delete message to use',
                zIndex: 10000,
                autoOpen: true,
                width: 'auto',
                resizable: false,
                width: 400,
                buttons: {
                    Yes: function () {
                        // $(obj).removeAttr('onclick');                                
                        // $(obj).parents('.Parent').remove();

                        //$('body').append('<h1>Confirm Dialog Result: <i>Yes</i></h1>');
                        $(this).dialog("close");
                        return true;
                    },
                    No: function () {
                        //$('body').append('<h1>Confirm Dialog Result: <i>No</i></h1>');
                        $(this).dialog("close");
                        return false;
                    }
                },
                close: function (event, ui) {
                    $(this).remove();
                }
            });
    };
</script>     
</body>
</html>

拯救
函数确认对话框(消息){
$('').appendTo('正文')
.html(“”+消息+“”?“”)
.对话({
莫代尔:是的,
标题:“删除要使用的邮件”,
zIndex:10000,
自动打开:对,
宽度:“自动”,
可调整大小:false,
宽度:400,
按钮:{
是:函数(){
//$(obj).removeAttr('onclick');
//$(obj).parents('.Parent').remove();
//$('body').append('Confirm Dialog Result:Yes');
$(此).dialog(“关闭”);
返回true;
},
否:函数(){
//$('body').append('Confirm Dialog Result:No');
$(此).dialog(“关闭”);
返回false;
}
},
关闭:功能(事件、用户界面){
$(this.remove();
}
});
};

问题是您的按钮默认为
type=“submit”
,您可以将其更改为
type=“button”
,并正常执行您的功能:

函数确认对话框(消息){
$('').appendTo('正文')
.html(“”+消息+“”?“”)
.对话({
莫代尔:是的,
标题:“删除要使用的邮件”,
zIndex:10000,
自动打开:对,
宽度:“自动”,
可调整大小:false,
宽度:400,
按钮:{
是:函数(){
$('body').append('Confirm Dialog Result:Yes');
$(此).dialog(“关闭”);
返回true;
},
否:函数(){
$('body').append('Confirm Dialog Result:No');
$(此).dialog(“关闭”);
返回false;
}
},
关闭:功能(事件、用户界面){
$(this.remove();
}
});
};

拯救

但当我单击“是”时,表单未发布:-(您需要使用
$('form')。单击