jQuery ダイアログのボタン(確認、キャンセル)を2つにするサンプル
環境
jquery 3.6.0
Google Chrome 106.0.5249.119
構文
$(セレクター名).dialog({
//モーダル表示
modal:true,
//ボタン名表示
buttons: {
“確認": function() {
$(this).dialog(“close");
}
buttonsオプションでボタンを2つに設定しています。
使用例
<!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() {
$("#div3").dialog({
modal:true, //モーダル表示
title:"警告情報", //タイトル
buttons: { //ボタン
"確認": function() {
$(this).dialog("close");
},
"キャンセル": function() {
$(this).dialog("close");
}
}
});
});
});
</script>
</head>
<body>
<div id="div3" style="display:none;">
<p>this is a test message</p>
</div>
<input type="button" id="btnshow" value="表示" />
</body>
</html>
実行結果
「表示」ボタンを押すと、ダイアログのボタン(確認、キャンセル)を二つにします。