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


当前回答

实现的简单方法:(在Javascript中执行此操作)

$("selector").dialog({
    autoOpen: false,
    open: function(event, ui) {   // It'll hide Close button
        $(".ui-dialog-titlebar-close", ui.dialog | ui).hide();
    },
    closeOnEscape: false,        // Do not close dialog on press Esc button
    show: {
        effect: "clip",
        duration: 500
    },
    hide: {
        effect: "blind",
        duration: 200
    },
    ....
});

其他回答

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

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

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

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

我是单行本的粉丝(他们在哪里工作!)。以下是对我有效的方法:

$("#dialog").siblings(".ui-dialog-titlebar").find(".ui-dialog-titlebar-close").hide();

罗伯特·麦克莱恩的回答对我不起作用。

然而,这对我来说确实有效:

$("#div").dialog({
   open: function() { $(".ui-dialog-titlebar-close").hide(); }
});

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

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

请检查它是否适合您。