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


当前回答

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

$('#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();

其他回答

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

$('#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();

对于那些正在使用DialogExtendjQueryExtension的用户,您可以使用可关闭选项来管理此功能以及此体面扩展提供的许多其他调整。

注意,如果您已经在使用DialogExtend,那么任何前述的DialogCSS黑客在初始化时都会被DialogExtend拦截。

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

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

请检查它是否适合您。

我捕捉对话框的关闭事件。然后,此代码删除<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();
  });
},

由于我发现我在应用程序的几个地方都在做这件事,所以我把它包装在一个插件中:

(function ($) {
   $.fn.dialogNoClose = function () {
      return this.each(function () {
         // hide the close button and prevent ESC key from closing
         $(this).closest(".ui-dialog").find(".ui-dialog-titlebar-close").hide();
         $(this).dialog("option", "closeOnEscape", false);
      });
   };
})(jQuery)

用法示例:

$("#dialog").dialog({ /* lots of options */ }).dialogNoClose();