如何删除jQueryUI创建的对话框上的关闭按钮(右上角的X)?
当前回答
以上这些都不起作用。真正有效的解决方案是:
$(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
})
请检查它是否适合您。
其他回答
我是单行本的粉丝(他们在哪里工作!)。以下是对我有效的方法:
$("#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();
});
},
这里还有一个选项,就是使用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>
Javascript。
$( ".selector" ).dialog({ dialogClass: 'no-close' });
工作示例
使用这个纯CSS行怎么样?我发现对于具有给定Id的对话框,这是最干净的解决方案:
.ui-dialog[aria-describedby="IdValueOfDialog"] .ui-dialog-titlebar-close { display: none; }
我觉得这样更好。
open: function(event, ui) {
$(this).closest('.ui-dialog').find('.ui-dialog-titlebar-close').hide();
}