jQueryUI modal dialog does not show close button (x)

后端 未结 15 2848
鱼传尺愫
鱼传尺愫 2020-12-12 23:45

I\'m using a jQuery modal dialog in my ASP .NET MVC 3 application. It works fine except for that there is no close button showing in the top right corner. How can I add thi

相关标签:
15条回答
  • 2020-12-13 00:01

    Using the principle of the idea user2620505 got result with implementation of addClass:

    ...
    open: function(){
        $('.ui-dialog-titlebar-close').addClass('ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only');
        $('.ui-dialog-titlebar-close').append('<span class="ui-button-icon-primary ui-icon ui-icon-closethick"></span><span class="ui-button-text">close</span>');
    }, 
    ...
    

    If English is bad forgive me, I am using Google Translate.

    0 讨论(0)
  • 2020-12-13 00:02

    While the op does not explicitly state they are using jquery ui and bootstrap together, an identical problem happens if you do. You can resolve the problem by loading bootstrap (js) before jquery ui (js). However, that will cause problems with button state colors.

    The final solution is to either use bootstrap or jquery ui, but not both. However, a workaround is:

        $('<div>dialog content</div>').dialog({
            title: 'Title',
            open: function(){
                var closeBtn = $('.ui-dialog-titlebar-close');
                closeBtn.append('<span class="ui-button-icon-primary ui-icon ui-icon-closethick"></span><span class="ui-button-text">close</span>');
            }
        });
    
    0 讨论(0)
  • 2020-12-13 00:03

    I had the same issue just add this function to the open dialog options and it worked sharm

    open: function(){
                var closeBtn = $('.ui-dialog-titlebar-close');
                closeBtn.append('<span class="ui-button-icon-primary ui-icon ui-icon-closethick"></span>');
            },
    

    and on close event you need to remove that

    close: function () {
                var closeBtn = $('.ui-dialog-titlebar-close');
                closeBtn.html('');}
    

    Complete example

    <div id="deleteDialog" title="Confirm Delete">
     Can you confirm you want to delete this event?
    </div> 
    
    $("#deleteDialog").dialog({
                    width: 400, height: 200,
                    modal: true,
                    open: function () {
                        var closeBtn = $('.ui-dialog-titlebar-close');
                        closeBtn.append('<span class="ui-button-icon-primary ui-icon ui-icon-closethick"></span>');
                    },
                    close: function () {
                        var closeBtn = $('.ui-dialog-titlebar-close');
                        closeBtn.html('');
                    },
                    buttons: {
                        "Confirm": function () {
                            calendar.fullCalendar('removeEvents', event._id);
                            $(this).dialog("close");
                        },
                        "Cancel": function () {
                            $(this).dialog("close");
                        }
                    }
                });
    
                $("#dialog").dialog("open");
    
    0 讨论(0)
  • 2020-12-13 00:03

    You need to add quotes around the "ok". That is the text of the button. As it is, the button's text is currently empty (and hence not displayed) because it is trying to resolve the value of that variable.

    Modal dialogs aren't meant to be closed in any fashion other than pressing the [ok] or [cancel] buttons. If you want the [x] in the right hand corner, set modal: false or just remove it altogether.

    0 讨论(0)
  • 2020-12-13 00:06

    Pure CSS Workaround:

    I was using both bootstrap and jQuery UI and changing the order of adding the scripts broke some other objects. I ended up using pure CSS workaround:

    .ui-dialog-titlebar-close {
      background: url("http://code.jquery.com/ui/1.10.3/themes/smoothness/images/ui-icons_888888_256x240.png") repeat scroll -93px -128px rgba(0, 0, 0, 0);
      border: medium none;
    }
    .ui-dialog-titlebar-close:hover {
      background: url("http://code.jquery.com/ui/1.10.3/themes/smoothness/images/ui-icons_222222_256x240.png") repeat scroll -93px -128px rgba(0, 0, 0, 0);
    }
    
    0 讨论(0)
  • 2020-12-13 00:07

    Another possibility is that you have the bootstrap library. Some version of bootstrap and jquery-ui have conflict with the .button() method, and if your bootstrap.js is placed after jquery-ui.js, the bootstrap .button() overrides your jquery button and the jquery-ui 'X' image would then not show up.

    see here: https://github.com/twbs/bootstrap/issues/6094

    This works (close box visible):

    <script src="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js"></script>
    <script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>
    

    This causes the issue:

    <script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>
    <script src="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js"></script>
    
    0 讨论(0)
提交回复
热议问题