Rob*_*ean 768 html css jquery jquery-ui jquery-ui-dialog
如何在jQuery UI创建的对话框中删除关闭按钮(右上角的X)?
Rob*_*ean 704
我发现这最终有效(注意第三行覆盖open函数,找到按钮并隐藏它):
$("#div2").dialog({
closeOnEscape: false,
open: function(event, ui) {
$(".ui-dialog-titlebar-close", ui.dialog || ui).hide();
}
});
Run Code Online (Sandbox Code Playgroud)
要隐藏所有对话框上的关闭按钮,您也可以使用以下CSS:
.ui-dialog-titlebar-close {
visibility: hidden;
}
Run Code Online (Sandbox Code Playgroud)
小智 356
这是另一个使用CSS的选项,它不会超过页面上的每个对话框.
CSS
.no-close .ui-dialog-titlebar-close {display: none }
Run Code Online (Sandbox Code Playgroud)
HTML
<div class="selector" title="No close button">
This is a test without a close button
</div>
Run Code Online (Sandbox Code Playgroud)
Javascript.
$( ".selector" ).dialog({ dialogClass: 'no-close' });
Run Code Online (Sandbox Code Playgroud)
小智 123
"最佳"答案对多个对话框不利.这是一个更好的解决方案.
open: function(event, ui) {
//hide close button.
$(this).parent().children().children('.ui-dialog-titlebar-close').hide();
},
Run Code Online (Sandbox Code Playgroud)
Gor*_*uan 86
您可以使用CSS隐藏关闭按钮而不是JavaScript:
.ui-dialog-titlebar-close{
display: none;
}
Run Code Online (Sandbox Code Playgroud)
mhu*_*mhu 48
如官方页面所示并由David建议:
创建一个样式:
.no-close .ui-dialog-titlebar-close {
display: none;
}
Run Code Online (Sandbox Code Playgroud)
然后,您可以简单地将no-close类添加到任何对话框,以隐藏它的关闭按钮:
$( "#dialog" ).dialog({
dialogClass: "no-close",
buttons: [{
text: "OK",
click: function() {
$( this ).dialog( "close" );
}
}]
});
Run Code Online (Sandbox Code Playgroud)
Mig*_*nte 41
我认为这更好.
open: function(event, ui) {
$(this).closest('.ui-dialog').find('.ui-dialog-titlebar-close').hide();
}
Run Code Online (Sandbox Code Playgroud)
Sal*_*n A 34
调用.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
Run Code Online (Sandbox Code Playgroud)
替代方法:
内部对话框事件处理程序,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
}
});
Run Code Online (Sandbox Code Playgroud)
仅供参考,对话框标记如下所示:
<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>
Run Code Online (Sandbox Code Playgroud)
FLY*_*FLY 25
Robert MacLean的回答对我不起作用.
但这对我有用:
$("#div").dialog({
open: function() { $(".ui-dialog-titlebar-close").hide(); }
});
Run Code Online (Sandbox Code Playgroud)
小智 9
$("#div2").dialog({
closeOnEscape: false,
open: function(event, ui) { $('#div2').parent().find('a.ui-dialog-titlebar-close').hide();}
});
Run Code Online (Sandbox Code Playgroud)
以上都不是.真正有效的解决方案是:
$(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
})
Run Code Online (Sandbox Code Playgroud)
请检查它是否适合您.
隐藏按钮的最佳方法是使用它的data-icon属性对其进行过滤:
$('#dialog-id [data-icon="delete"]').hide();
Run Code Online (Sandbox Code Playgroud)
小智 6
open: function(event, ui) {
//hide close button.
$(this).parent().children().children('.ui-dialog-titlebar-close').click(function(){
$("#dhx_combo_list").remove();
});
},
Run Code Online (Sandbox Code Playgroud)
yaaaay!它确实有效!我抓住了对话框的关闭事件.在上面的代码中,它删除了div(#dhx_combo_list).
太好了,谢谢大家!
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
Run Code Online (Sandbox Code Playgroud)
Dialog小部件添加的关闭按钮具有类'ui-dialog-titlebar-close',因此在初始调用.dialog()之后,您可以使用这样的语句再次删除关闭按钮:它可以工作..
$( 'a.ui-dialog-titlebar-close' ).remove();
Run Code Online (Sandbox Code Playgroud)
$(".ui-button-icon-only").hide();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
400540 次 |
| 最近记录: |