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

有帮助吗?

解决方案

我发现这个工作到底(注意第三行重写开放函数查找按钮,并隐藏它):

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

要隐藏你可以使用下面的CSS过所有对话框关闭按钮:

.ui-dialog-titlebar-close {
    visibility: hidden;
}

其他提示

下面是另一种选择只使用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' });

工作实施例

“最佳”答案将不利于多个对话。这里是一个更好的解决方案。

open: function(event, ui) { 
    //hide close button.
    $(this).parent().children().children('.ui-dialog-titlebar-close').hide();
},

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

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

如果您不希望影响到所有的模态,你可以使用如下规则

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

和应用.hide-close-btn到对话框的顶部节点

如图官方并建议由大卫:

创建样式:

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

然后,你可以简单地无密切类添加到任何对话,以隐藏它的关闭按钮:

$( "#dialog" ).dialog({
    dialogClass: "no-close",
    buttons: [{
        text: "OK",
        click: function() {
            $( this ).dialog( "close" );
        }
    }]
});

我认为这是更好的。

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

一旦称为元件上.dialog(),可以定位在任何方便的时间的关闭按钮(和其他对话标记),而不使用的事件处理程序:

$("#div2").dialog({                    // call .dialog method to create the dialog markup
    autoOpen: false
});
$("#div2").dialog("widget")            // get the dialog widget element
    .find(".ui-dialog-titlebar-close") // find the close button for this dialog
    .hide();                           // hide it

替代方法:

在对话事件处理程序,this指元件被“dialogged”和$(this).parent()指对话框标记容器,所以:

$("#div3").dialog({
    open: function() {                         // open event handler
        $(this)                                // the element being dialogged
            .parent()                          // get the dialog widget element
            .find(".ui-dialog-titlebar-close") // find the close button for this dialog
            .hide();                           // hide it
    }
});

FYI,对话框标记看起来像这样:

<div class="ui-dialog ui-widget ui-widget-content ui-corner-all ui-draggable ui-resizable">
    <!-- ^--- this is the dialog widget -->
    <div class="ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix">
        <span class="ui-dialog-title" id="ui-dialog-title-dialog">Dialog title</span>
        <a class="ui-dialog-titlebar-close ui-corner-all" href="#"><span class="ui-icon ui-icon-closethick">close</span></a>
    </div>
    <div id="div2" style="height: 200px; min-height: 200px; width: auto;" class="ui-dialog-content ui-widget-content">
        <!-- ^--- this is the element upon which .dialog() was called -->
    </div>
</div>

这里演示

罗伯特·麦克莱恩的回答并没有为我工作。

然而,这对我的工作:

$("#div").dialog({
   open: function() { $(".ui-dialog-titlebar-close").hide(); }
});
$("#div2").dialog({
   closeOnEscape: false,
   open: function(event, ui) { $('#div2').parent().find('a.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
})

请检查它是否适合你。

以隐藏按钮的最佳方式是与它的数据属性的图标来过滤它:

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

有关的停用类,短代码:

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

可以被使用。

由对话框控件添加的关闭按钮具有类的用户界面,对话框的标题栏关闭',所以你以后初始调用.dialog(),你可以用这样的语句来再次删除关闭按钮: 它的工作原理..

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

我赶对话框的关闭事件。此代码然后移除<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();
  });
},
$(".ui-button-icon-only").hide();

您还可以删除你的标题行:

<div data-role="header">...</div>

其去除的关闭按钮。

document.querySelector('.ui-dialog-titlebar-close').style.display = 'none'

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

因为我发现我在我的应用程序的几个地方这样做,我包裹在一个插件:

(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();

我的俏皮话风扇(他们在哪里工作!)。下面是我的什么作品:

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

如何使用这种纯CSS线? 我发现这个用于与给定的ID的对话的干净的解决方案:

.ui-dialog[aria-describedby="IdValueOfDialog"] .ui-dialog-titlebar-close { display: none; }

可以用下面的代码移除的关闭按钮。还有其他的选择,以及你可能打有用的。

$('#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();
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top