문제

닫기 버튼 ( 엑스 오른쪽 상단 코너에서) 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 "대화식"및 요소를 나타냅니다 $(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
    }
});

참고로 대화 상자 마크 업은 다음과 같습니다.

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

여기 데모

Robert MacLean의 대답은 저에게 효과가 없었습니다.

그러나 이것은 나에게 효과가 있습니다.

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

그것이 당신에게 효과가 있는지 확인하십시오.

버튼을 숨기는 가장 좋은 방법은 Data-ICON 속성으로 필터링하는 것입니다.

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

사용될 수있다.

대화 상자 위젯에 의해 추가 된 닫기 버튼에는 클래스 'UI-Dialog-Titlebar-Close'가 있으므로 .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();

나는 1 라이너의 팬입니다 (그들이 일하는 곳!). 다음은 저에게 효과가 있습니다.

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