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


当前回答

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

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

其他回答

http://jsfiddle.net/marcosfromero/aWyNn/

$('#yourdiv').                 // Get your box ...
  dialog().                    // ... and turn it into dialog (autoOpen: false also works)
  prev('.ui-dialog-titlebar'). // Get title bar,...
  find('a').                   // ... then get the X close button ...
  hide();                      // ... and hide it

我捕捉对话框的关闭事件。然后,此代码删除<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来隐藏关闭按钮,而不是JavaScript:

.ui-dialog-titlebar-close{
    display: none;
}

如果你不想影响所有的情态动词,你可以使用如下规则

.hide-close-btn .ui-dialog-titlebar-close{
    display: none;
}

并将.hide close btn应用于对话框的顶部节点

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

$( 'a.ui-dialog-titlebar-close' ).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
})

请检查它是否适合您。