如何删除jQueryUI创建的对话框上的关闭按钮(右上角的X)?


当前回答

这里还有一个选项,就是使用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' });

工作示例

其他回答

Dialog小部件添加的关闭按钮具有类“ui Dialog titlebar close”,因此在首次调用.Dialog()后,您可以使用如下语句再次删除关闭按钮:它起作用了。。

$( 'a.ui-dialog-titlebar-close' ).remove();

隐藏按钮的最佳方法是使用其数据图标属性对其进行过滤:

$('#dialog-id [data-icon="delete"]').hide();

您可以使用以下代码删除关闭按钮。还有其他的选择,你可能会觉得有用。

$('#dialog-modal').dialog({
    //To hide the Close 'X' button
    "closeX": false,
    //To disable closing the pop up on escape
    "closeOnEscape": false,
    //To allow background scrolling
    "allowScrolling": true
    })
//To remove the whole title bar
.siblings('.ui-dialog-titlebar').remove();

以上这些都不起作用。真正有效的解决方案是:

$(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
})

请检查它是否适合您。

$("#div2").dialog({
   closeOnEscape: false,
   open: function(event, ui) { $('#div2').parent().find('a.ui-dialog-titlebar-close').hide();}
});