2014年11月10日月曜日

JQuery UIを使ってみる―Dialog編―

JQuery UIを使えば、ダイアログの作成も簡単です。ボタンを配置して自由に関数を設定できるので、応用範囲は広そうですね。 

今回は二段構成にしてみました。ちなみに、同じダイアログを複数開かないようにデフォルトで設定されているようです。


You are learning JavaScript. This message is popped up because of JQuery UI Dialog.
This is a second dialog, that is modal!


<body>
    <button id="button_dialog">Open Dialog</button>
    <div id="msg_dialog">
        You are learning JavaScript. This message is popped up because of JQuery UI Dialog.
    </div>

    <div id="msg_dialog2">
        This is a second dialog, that is modal!
    </div>

    <script>
        $(function () {
            $('#button_dialog').click(function () {
                $('#msg_dialog').dialog('open');
            });
            $('#msg_dialog').dialog({
                //without this option, dialog pop up when a page opens 
                autoOpen: false,
                buttons:{
                    "Close": function(){
                        $(this).dialog('close');   
                    },
                    "Open": function(){
                        $('#msg_dialog2').dialog('open');
                    }
                },
                title: 'Dialog1' 
            });
            $('#msg_dialog2').dialog({
               autoOpen: false,
               buttons:{
                   "Close": function(){
                        $('#msg_dialog').dialog('close');
                        $(this).dialog('close');   
                   }
               },
               modal: true,
               title: 'Dialog2' 
            });
        });   
    </script>
</body>

0 件のコメント:

コメントを投稿