Jak usunąć przycisk zamknięcia w oknie jQuery UI?

Jak usunąć przycisk zamykania ( X w prawym górnym rogu) w oknie dialogowym utworzonym przez jQuery UI?

Author: Robert MacLean, 2009-05-22

24 answers

Znalazłem, że to działa na końcu (zauważ, że trzecia linia nadpisuje funkcję open, która znajduje przycisk i ukrywa go):

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

Aby ukryć przycisk zamykania na wszystkich oknach dialogowych, możesz również użyć następującego CSS:

.ui-dialog-titlebar-close {
    visibility: hidden;
}
 715
Author: Robert MacLean,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2019-07-29 15:10:04

Tutaj jest inna opcja po prostu za pomocą CSS, który nie Over jeździć każde okno dialogowe na stronie.

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' });

Przykład Roboczy

 363
Author: David,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-02-07 16:23:30

"Najlepsza" odpowiedź nie będzie dobra dla wielu okien dialogowych. oto lepsze rozwiązanie.

open: function(event, ui) { 
    //hide close button.
    $(this).parent().children().children('.ui-dialog-titlebar-close').hide();
},
 126
Author: Earl,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-03-25 05:24:52

Możesz użyć CSS, aby ukryć przycisk zamykania zamiast JavaScript:

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

Jeśli nie chcesz wpływać na wszystkie Modale, możesz użyć reguły takiej jak

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

I Zastosuj .hide-close-btn do górnego węzła okna dialogowego

 88
Author: Gordian Yuan,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2019-03-20 09:18:47

Jak pokazano na oficjalnej stronie i zasugerował Dawid:

Utwórz styl:

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

Następnie możesz po prostu dodać klasę no-close do dowolnego okna dialogowego, aby ukryć przycisk zamykania:

$( "#dialog" ).dialog({
    dialogClass: "no-close",
    buttons: [{
        text: "OK",
        click: function() {
            $( this ).dialog( "close" );
        }
    }]
});
 48
Author: mhu,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-03-19 12:26:42

Tak będzie lepiej.

open: function(event, ui) {
  $(this).closest('.ui-dialog').find('.ui-dialog-titlebar-close').hide();
}
 41
Author: Miguel Galante,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2010-11-26 19:04:30

Po wywołaniu .dialog() na elemencie, możesz zlokalizować przycisk zamykania (i inne znaczniki dialogowe) w dowolnym dogodnym czasie bez użycia narzędzi obsługi zdarzeń:

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

Metoda alternatywna:

Wewnątrz narzędzi obsługi zdarzeń dialogowych, this odnosi się do elementu będącego "dialogowym", a $(this).parent() odnosi się do kontenera znaczników dialogowych, więc:

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

Dla twojej wiadomości, znaczniki dialogowe wyglądają tak:

<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>

Demo tutaj

 36
Author: Salman A,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-08-04 10:02:56

Odpowiedź Roberta Macleana nie zadziałała.

To jednak działa dla mnie:

$("#div").dialog({
   open: function() { $(".ui-dialog-titlebar-close").hide(); }
});
 25
Author: FLY,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-04-12 08:17:45
$("#div2").dialog({
   closeOnEscape: false,
   open: function(event, ui) { $('#div2').parent().find('a.ui-dialog-titlebar-close').hide();}
});
 9
Author: Alok Vad,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-09-16 16:50:28

Żadne z powyższych nie działa. Rozwiązanie, które naprawdę działa to:

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

Proszę sprawdzić, czy to działa dla Ciebie.

 9
Author: Michael Zelensky,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-02-10 18:48:46

Najlepszym sposobem ukrycia przycisku jest filtrowanie go atrybutem data-icon:

$('#dialog-id [data-icon="delete"]').hide();
 7
Author: ibrahimab,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-02-02 16:45:12

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
 6
Author: marcosfromero,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-03-15 01:15:28

Dla dezaktywacji klasy, krótki kod:

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

Może być stosowany.

 6
Author: Caniko,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-10-19 12:46:47

Przycisk zamykania dodany przez widżet okna dialogowego ma klasę "UI-dialog-titlebar-close" , więc po pierwszym wywołaniu do .dialog (), możesz użyć takiej instrukcji, aby ponownie usunąć przycisk zamykania: To działa..

$( 'a.ui-dialog-titlebar-close' ).remove();
 6
Author: Sonal S.,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-12-14 12:09:25

Wyłapuję Zdarzenie zamknięcia okna dialogowego. Kod ten usuwa <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();
  });
},
 6
Author: ruwan,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2019-03-25 18:41:43
$(".ui-button-icon-only").hide();
 5
Author: Cos,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-05-05 01:13:10

Możesz również usunąć linię nagłówka:

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

Który usuwa przycisk zamykania.

 3
Author: mellow-yellow,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-11-21 05:18:51
document.querySelector('.ui-dialog-titlebar-close').style.display = 'none'
 2
Author: Matthew Wastrodowski,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-01-13 12:23:56

Łatwy sposób na osiągnięcie: (zrób to w swoim 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
    },
    ....
});
 2
Author: Arsman Ahmad,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-06-13 11:28:55

Ponieważ odkryłem, że robię to w kilku miejscach w mojej aplikacji, owinąłem go w wtyczkę:

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

Przykład Użycia:

$("#dialog").dialog({ /* lots of options */ }).dialogNoClose();
 1
Author: bmode,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-09-21 02:29:31

Jestem fanem one-linerów (gdzie pracują!). Oto, co działa dla mnie:

$("#dialog").siblings(".ui-dialog-titlebar").find(".ui-dialog-titlebar-close").hide();
 1
Author: wordragon,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-09-15 16:40:40

Co powiesz na użycie tej czystej linii CSS? Uważam to za najczystsze rozwiązanie dla okna dialogowego o podanym Id:

.ui-dialog[aria-describedby="IdValueOfDialog"] .ui-dialog-titlebar-close { display: none; }
 0
Author: Chrisman,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2019-04-12 08:39:10

To jest dla jQuery UI 1.12. Dodałem następujące ustawienie konfiguracji dla opcji 'classes'

        classes: {
            'ui-dialog-titlebar-close': 'hidden',
        },

Inicjalizacja całego okna dialogowego wygląda następująco:

ConfirmarSiNo(titulo, texto, idPadre, fnCerrar) {
    const DATA_RETORNO = 'retval';
    $('confirmar-si-no').dialog({
        title: titulo,
        modal: true,
        classes: {
            'ui-dialog-titlebar-close': 'hidden',
        },
        appendTo: `#${idPadre}`,
        open: function fnOpen() { $(this).text(texto); },
        close: function fnClose() {
            let eligioSi = $(this).data(DATA_RETORNO) == true;
            setTimeout(function () { fnCerrar(eligioSi); }, 30);
        },
        buttons: {
            'Si, por favor': function si() { $(this).data(DATA_RETORNO, true); $(this).dialog("close"); },
            'No, gracias': function no() { $(this).data(DATA_RETORNO, false); $(this).dialog("close"); }
        }
    });
}

Używam następującego wywołania skryptu, aby go wyświetlić:

ConfirmarSiNo('Titulo',
              '¿Desea actualizar?',
              idModalPadre,
              (eligioSi) => {
                            if (eligioSi) {
                                this.$tarifa.val(tarifa.tarifa);
                                this.__ActualizarTarifa(tarifa);
                            }
                        });

W html body mam następujący div, który zawiera okno dialogowe:

<div class="modal" id="confirmar-si-no" title="" aria-labelledby="confirmacion-label">
    mensaje
</div>

Wynik końcowy to:

Tutaj wpisz opis obrazka

Funkcja 'ConfirmarSiNo' opiera się na' Whome 'odpowiedź na post jak zaimplementować okno dialogowe "potwierdzenie" w JQuery UI dialog?

 0
Author: Chesare,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2020-12-08 20:28:32

Możesz usunąć przycisk zamykania za pomocą poniższego kodu. Istnieją również inne opcje, które mogą być przydatne do walki.

$('#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();
 -1
Author: bpjoshi,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-03-27 07:49:07