jQuery ダイアログの大きさを指定するサンプル

環境
jquery 3.6.0
Google Chrome 106.0.5249.119

構文
$(セレクター名).dialog({
modal:true, //モーダル表示
width:数値, //ダイアログの横幅(px)
height:数値, //ダイアログの縦幅(px)
widthオプションとheightオプションで、ダイアログの横幅と縦幅を指定しています。
単位はpxです。

使用例

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() {
$("#btnshow").click(function() {
$("#cft").dialog({
modal:true, //モーダル表示
width:250, //ダイアログの横幅(px)
height:250, //ダイアログの縦幅(px)
title:"警告情報", //タイトル
buttons: { //ボタン
"確認": function() {
$(this).dialog("close");
}
}
});
});
});
</script>
</head>
<body>
<div id="cft" style="display:none;">
<p>this is a test message</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() { $("#btnshow").click(function() { $("#cft").dialog({ modal:true, //モーダル表示 width:250, //ダイアログの横幅(px) height:250, //ダイアログの縦幅(px) title:"警告情報", //タイトル buttons: { //ボタン "確認": function() { $(this).dialog("close"); } } }); }); }); </script> </head> <body> <div id="cft" style="display:none;"> <p>this is a test message</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() {
      $("#btnshow").click(function() {
            $("#cft").dialog({
                  modal:true, //モーダル表示
                  width:250, //ダイアログの横幅(px)
                  height:250, //ダイアログの縦幅(px)
                  title:"警告情報", //タイトル
                  buttons: { //ボタン
                  "確認": function() {
                        $(this).dialog("close");
                        }
                  }
            });
      });
});
</script>
</head>
<body>

<div id="cft" style="display:none;">
<p>this is a test message</p>
</div>
<input type="button" id="btnshow" value="表示" />

</body>
</html>

結果
「表示」ボタンを押すと、ダイアログの横幅(250)と縦幅(250)画面が表示されます。

jQuery

Posted by arkgame