如何删除jQueryUI创建的对话框上的关闭按钮(右上角的X)?
当前回答
您可以使用CSS来隐藏关闭按钮,而不是JavaScript:
.ui-dialog-titlebar-close{
display: none;
}
如果你不想影响所有的情态动词,你可以使用如下规则
.hide-close-btn .ui-dialog-titlebar-close{
display: none;
}
并将.hide close btn应用于对话框的顶部节点
其他回答
我是单行本的粉丝(他们在哪里工作!)。以下是对我有效的方法:
$("#dialog").siblings(".ui-dialog-titlebar").find(".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();
});
},
我最终发现这是有效的(请注意,第三行覆盖了打开的函数,该函数查找按钮并隐藏它):
$("#div2").dialog({
closeOnEscape: false,
open: function(event, ui) {
$(".ui-dialog-titlebar-close", ui.dialog || ui).hide();
}
});
要隐藏所有对话框上的关闭按钮,也可以使用以下CSS:
.ui-dialog-titlebar-close {
visibility: hidden;
}
由于我发现我在应用程序的几个地方都在做这件事,所以我把它包装在一个插件中:
(function ($) {
$.fn.dialogNoClose = function () {
return this.each(function () {
// hide the close button and prevent ESC key from closing
$(this).closest(".ui-dialog").find(".ui-dialog-titlebar-close").hide();
$(this).dialog("option", "closeOnEscape", false);
});
};
})(jQuery)
用法示例:
$("#dialog").dialog({ /* lots of options */ }).dialogNoClose();
一旦对元素调用了.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
替代方法:
在对话框事件处理程序中,这是指“dialogged”元素,$(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>
此处演示
推荐文章
- 使伸缩项目正确浮动
- 可以在setInterval()内部调用clearInterval()吗?
- 无法读取未定义的属性“msie”- jQuery工具
- 如何取消最大高度?
- 形式内联内的形式水平在twitter bootstrap?
- 自定义元素在HTML5中有效吗?
- 如何选择在最后一个子元素之前的元素?
- 如何触发自动填充在谷歌Chrome?
- jQuery:执行同步AJAX请求
- CSS变换,锯齿边缘在铬
- 创建圈div比使用图像更容易的方法?
- 强迫孩子服从父母的弯曲边界在CSS
- jQuery表格排序
- 如何禁用文本选择使用jQuery?
- 为什么Chrome浏览器不正确地确定页面是在不同的语言,并提供翻译?