jQuery UIによって作成されたダイアログボックスの閉じるボタン(右上隅のX )を削除するにはどうすればよいですか?
25 に答える
これが最終的に機能することがわかりました(ボタンを見つけて非表示にするopen関数をオーバーライドする3行目に注意してください):
$("#div2").dialog({
closeOnEscape: false,
open: function(event, ui) {
$(".ui-dialog-titlebar-close", ui.dialog || ui).hide();
}
});
すべてのダイアログで閉じるボタンを非表示にするには、次の CSS も使用できます。
.ui-dialog-titlebar-close {
visibility: hidden;
}
これは、ページ上のすべてのダイアログを上書きしない CSS を使用する別のオプションです。
CSS
.no-close .ui-dialog-titlebar-close {display: none }
HTML
<div class="selector" title="No close button">
This is a test without a close button
</div>
ジャバスクリプト。
$( ".selector" ).dialog({ dialogClass: 'no-close' });
「最良の」答えは、複数のダイアログには適していません。これがより良い解決策です。
open: function(event, ui) {
//hide close button.
$(this).parent().children().children('.ui-dialog-titlebar-close').hide();
},
JavaScriptの代わりにCSSを使用して閉じるボタンを非表示にすることができます。
.ui-dialog-titlebar-close{
display: none;
}
すべてのモーダルに影響を与えたくない場合は、次のようなルールを使用できます。
.hide-close-btn .ui-dialog-titlebar-close{
display: none;
}
そして.hide-close-btn
、ダイアログのトップノードに適用します
公式ページに示され、 Davidが提案したように:
スタイルを作成します。
.no-close .ui-dialog-titlebar-close {
display: none;
}
次に、閉じるボタンを非表示にするために、no-close クラスを任意のダイアログに追加するだけです。
$( "#dialog" ).dialog({
dialogClass: "no-close",
buttons: [{
text: "OK",
click: function() {
$( this ).dialog( "close" );
}
}]
});
これは良いと思います。
open: function(event, ui) {
$(this).closest('.ui-dialog').find('.ui-dialog-titlebar-close').hide();
}
要素を呼び出すと.dialog()
、イベントハンドラーを使用せずに、いつでも閉じるボタン(およびその他のダイアログマークアップ)を見つけることができます。
$("#div2").dialog({ // call .dialog method to create the dialog markup
autoOpen: false
});
$("#div2").dialog("widget") // get the dialog widget element
.find(".ui-dialog-titlebar-close") // find the close button for this dialog
.hide(); // hide it
別の方法:
ダイアログイベントハンドラー内で、this
「ダイアログ」されている要素を$(this).parent()
参照し、ダイアログマークアップコンテナーを参照します。したがって、次のようになります。
$("#div3").dialog({
open: function() { // open event handler
$(this) // the element being dialogged
.parent() // get the dialog widget element
.find(".ui-dialog-titlebar-close") // find the close button for this dialog
.hide(); // hide it
}
});
参考までに、ダイアログのマークアップは次のようになります。
<div class="ui-dialog ui-widget ui-widget-content ui-corner-all ui-draggable ui-resizable">
<!-- ^--- this is the dialog widget -->
<div class="ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix">
<span class="ui-dialog-title" id="ui-dialog-title-dialog">Dialog title</span>
<a class="ui-dialog-titlebar-close ui-corner-all" href="#"><span class="ui-icon ui-icon-closethick">close</span></a>
</div>
<div id="div2" style="height: 200px; min-height: 200px; width: auto;" class="ui-dialog-content ui-widget-content">
<!-- ^--- this is the element upon which .dialog() was called -->
</div>
</div>
Robert MacLean の答えはうまくいきませんでした。
ただし、これは私にとってはうまくいきます:
$("#div").dialog({
open: function() { $(".ui-dialog-titlebar-close").hide(); }
});
上記のいずれも機能しません。実際に機能するソリューションは次のとおりです。
$(function(){
//this is your dialog:
$('#mydiv').dialog({
// Step 1. Add an extra class to our dialog to address the dialog directly. Make sure that this class is not used anywhere else:
dialogClass: 'my-extra-class'
})
// Step 2. Hide the close 'X' button on the dialog that you marked with your extra class
$('.my-extra-class').find('.ui-dialog-titlebar-close').css('display','none');
// Step 3. Enjoy your dialog without the 'X' link
})
それがあなたのために働くかどうかを確認してください。
$("#div2").dialog({
closeOnEscape: false,
open: function(event, ui) { $('#div2').parent().find('a.ui-dialog-titlebar-close').hide();}
});
ボタンを非表示にする最良の方法は、ボタンの data-icon 属性でフィルターすることです。
$('#dialog-id [data-icon="delete"]').hide();
クラスを非アクティブ化するための短いコード:
$(".ui-dialog-titlebar-close").hide();
使用できます。
ダイアログ ボックスのクローズ イベントをキャッチします。<div>
次に、このコードは( #dhx_combo_list
)を削除します。
open: function(event, ui) {
//hide close button.
$(this).parent().children().children('.ui-dialog-titlebar-close').click(function(){
$("#dhx_combo_list").remove();
});
},
http://jsfiddle.net/marcosfromero/aWyNn/
$('#yourdiv'). // Get your box ...
dialog(). // ... and turn it into dialog (autoOpen: false also works)
prev('.ui-dialog-titlebar'). // Get title bar,...
find('a'). // ... then get the X close button ...
hide(); // ... and hide it
ダイアログウィジェットによって追加された閉じるボタンにはクラス「ui-dialog-titlebar-close」があるため、.dialog() への最初の呼び出しの後、次のようなステートメントを使用して閉じるボタンを再度削除できます。
$( 'a.ui-dialog-titlebar-close' ).remove();
ヘッダー行を削除することもできます:
<div data-role="header">...</div>
閉じるボタンを削除します。
document.querySelector('.ui-dialog-titlebar-close').style.display = 'none'