如何删除jQueryUI创建的对话框上的关闭按钮(右上角的X)?
当前回答
使用这个纯CSS行怎么样?我发现对于具有给定Id的对话框,这是最干净的解决方案:
.ui-dialog[aria-describedby="IdValueOfDialog"] .ui-dialog-titlebar-close { display: none; }
其他回答
$(".ui-button-icon-only").hide();
使用这个纯CSS行怎么样?我发现对于具有给定Id的对话框,这是最干净的解决方案:
.ui-dialog[aria-describedby="IdValueOfDialog"] .ui-dialog-titlebar-close { display: none; }
对于多个对话框,“最佳”答案并不好。这里有一个更好的解决方案。
open: function(event, ui) {
//hide close button.
$(this).parent().children().children('.ui-dialog-titlebar-close').hide();
},
我最终发现这是有效的(请注意,第三行覆盖了打开的函数,该函数查找按钮并隐藏它):
$("#div2").dialog({
closeOnEscape: false,
open: function(event, ui) {
$(".ui-dialog-titlebar-close", ui.dialog || ui).hide();
}
});
要隐藏所有对话框上的关闭按钮,也可以使用以下CSS:
.ui-dialog-titlebar-close {
visibility: hidden;
}
以上这些都不起作用。真正有效的解决方案是:
$(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
})
请检查它是否适合您。