jQuery autoOpenオプションでダイアログの表示を制御するサンプル

環境
jquery 3.6.0
Google Chrome 106.0.5249.119

構文
1.autoOpenオプションでダイアログの表示を制御
$(セレクター名).dialog({
autoOpen: false,//呼ばれるまで非表示
modal:true, //モーダル表示
2.ダイアログを開きます
$(セレクター名).dialog(“open");

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<script>
$(function() {
$("#cft").dialog({
//呼ばれるまで非表示
autoOpen: false,
//モーダル表示
modal:true,
//タイトル
title:"警告表示",
buttons: { //ボタン
"確認": function() {
$(this).dialog("close");
}
}
});
$("#btnshow").click(function() {
$("#cft").dialog("open");
});
});
</script>
</head>
<body>
<div id="cft" >
<p>test 1234578</p>
</div>
<input type="button" id="btnshow" value="表示" />
</body>
</html>
<!DOCTYPE html> <html> <head> <link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script> <script> $(function() { $("#cft").dialog({ //呼ばれるまで非表示 autoOpen: false, //モーダル表示 modal:true, //タイトル title:"警告表示", buttons: { //ボタン "確認": function() { $(this).dialog("close"); } } }); $("#btnshow").click(function() { $("#cft").dialog("open"); }); }); </script> </head> <body> <div id="cft" > <p>test 1234578</p> </div> <input type="button" id="btnshow" value="表示" /> </body> </html>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>

<script>
$(function() {
      $("#cft").dialog({
       //呼ばれるまで非表示
            autoOpen: false,
         //モーダル表示
            modal:true, 
        //タイトル
            title:"警告表示", 
            buttons: { //ボタン
            "確認": function() {
                  $(this).dialog("close");
                  }
            }
      });
      $("#btnshow").click(function() {
            $("#cft").dialog("open");
      });
});
</script>
</head>
<body>

<div id="cft" >
<p>test 1234578</p>
</div>
<input type="button" id="btnshow" value="表示" />
</body>
</html>

結果
「表示」ボタンを押すとダイアログが開きます。ダイアログの表示はautoOpenオプションで非表示になります。

jQuery

Posted by arkgame