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


当前回答

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

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

其他回答

您可以使用CSS来隐藏关闭按钮,而不是JavaScript:

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

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

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

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

实现的简单方法:(在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
    },
    ....
});

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

我觉得这样更好。

open: function(event, ui) {
  $(this).closest('.ui-dialog').find('.ui-dialog-titlebar-close').hide();
}

对于停用类,短代码:

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

可以使用。