Jquery dialog , Confirm callBack 받기

 

<html>
<head>
<script src="./Script/jquery-3.3.1.js"></script>
<script src="./Script/jquery-ui.min.js"></script>

<link rel="stylesheet" type="text/css" href="./Content/diagram.css">
<link rel="stylesheet" type="text/css" href="./Content/jquery-ui.min.css"> 
<link rel="stylesheet" type="text/css" href="./Content/jquery-ui.theme.min.css"> 
<script>
var bot ={};
var messageDialog;
$(document).ready(function(){

    bot.windows ={
        alert : function(msg){
            alert(msg);
        },
        confirm : function(msgCallBack){
            //confirm("test");

            $("#msgInfo").dialog({
                            autoOpen: false,
                            height: 200,
                            width: 350,
                            modal: true,

                            buttons: {
                                Ok: function () {
                                    msgCallBack('OK');
                                    $(this).dialog("close");
                                },
                                Cancel: function () {
                                    msgCallBack('CANCEL');
                                    $(this).dialog("close");
                                }
                            }
                        });

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

   //요렇게 써도됨
   messageDialog  = function(msgCallBack){  
                        $("#msgInfo").dialog({
                            autoOpen: false,
                            height: 200,
                            width: 350,
                            modal: true,

                            buttons: {
                                Ok: function () {
                                    msgCallBack('OK');
                                    $(this).dialog("close");
                                },
                                Cancel: function () {
                                    msgCallBack('CANCEL');
                                    $(this).dialog("close");
                                }
                            }
                        });

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

                    }


    test();
});

function test(){

   // 정상실행
   // var result =   bot.windows.confirm("alert test");
   // console.log(result);

    //정상실행
    // messageDialog(  
    //     function msgCallBack( msg){
    //        console.log(msg);
    //     });

    var result =   bot.windows.confirm( 
        function msgCallBack( msg){
            console.log(msg); //여기서 결과값 반환
         });

   }

</script>
</head>

<body>

<input type="button" value="test" onclick="test()">

<div id="msgInfo" title="Confirm">
        <div id="messageText" class="elementText"></div>
</div>
</body>
</html>

 

+ Recent posts