如何在jQuery UI创建的对话框中删除关闭按钮(右上角的X )?
#1楼
一旦在元素上调用.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
}
});
仅供参考,对话框标记如下所示:
#2楼
Robert MacLean的回答对我不起作用。
但这对我有用:
$("#div").dialog({
open: function() { $(".ui-dialog-titlebar-close").hide(); }
});
#3楼
您还可以删除标题行:
删除关闭按钮。
#4楼
Dialog小部件添加的关闭按钮具有类'ui-dialog-titlebar-close',因此在初始调用.dialog()之后,您可以使用这样的语句再次删除关闭按钮:它可以工作..
$( 'a.ui-dialog-titlebar-close' ).remove();
#5楼
如官方页面所示并由David建议:
创建一个样式:
.no-close .ui-dialog-titlebar-close {
display: none;
}
然后,您可以简单地将no-close类添加到任何对话框,以隐藏它的关闭按钮:
$( "#dialog" ).dialog({
dialogClass: "no-close",
buttons: [{
text: "OK",
click: function() {
$( this ).dialog( "close" );
}
}]
});