jquery UI dialog: how to initialize without a title bar?

前端 未结 23 1689
春和景丽
春和景丽 2020-11-29 15:03

Is it possible to open a jQuery UI Dialog without a title bar?

相关标签:
23条回答
  • 2020-11-29 15:39

    This is the easiest way to do it and it will only remove the titlebar in that one specific dialog;

    $('.dialog_selector').find('.ui-dialog-titlebar').hide();
    
    0 讨论(0)
  • 2020-11-29 15:40

    go to your jquery-ui.js (in my case jquery-ui-1.10.3.custom.js) and search for this._createTitlebar(); and comment it.

    now anyone of yours dialog will appear with headers. If you want to customize the header just go to _createTitlebar(); and edit the code inside.

    by

    0 讨论(0)
  • 2020-11-29 15:41

    You can use jquery to hide titlebar after using dialogClass when initializing the dialog.

    during init :

    $('.selector').dialog({
        dialogClass: 'yourclassname'
    });
    
    $('.yourclassname div.ui-dialog-titlebar').hide();
    

    By using this method, you don't need to change your css file, and this is dynamic too.

    0 讨论(0)
  • 2020-11-29 15:41

    I like overriding jQuery widgets.

    (function ($) {
        $.widget("sauti.dialog", $.ui.dialog, {
            options: {
                headerVisible: false
            },
            _create: function () {
                // ready to generate button
                this._super("_create"); // for 18 would be $.Widget.prototype._create.call(this);
                // decide if header is visible
                if(this.options.headerVisible == false)
                    this.uiDialogTitlebar.hide();
            },
            _setOption: function (key, value) {
                this._super(key, value); // for 1.8 would be $.Widget.prototype._setOption.apply( this, arguments );
                if (key === "headerVisible") {
                    if (key == false)
                        this.uiDialogTitlebar.hide();
                    else
                        this.uiDialogTitlebar.show();
                    return;
                }
            }
        });
    })(jQuery);
    

    So you can now setup if you want to show title bar or not

       $('#mydialog').dialog({
          headerVisible: false // or true
    });
    
    0 讨论(0)
  • 2020-11-29 15:41

    This next form fixed me the problem.

    $('#btnShow').click(function() {
      $("#basicModal").dialog({
        modal: true,
        height: 300,
        width: 400,
        create: function() {
          $(".ui-dialog").find(".ui-dialog-titlebar").css({
            'background-image': 'none',
            'background-color': 'white',
            'border': 'none'
          });
        }
      });
    });
    #basicModal {
      display: none;
    }
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>
    <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/themes/smoothness/jquery-ui.css" />
    <div id="basicModal">
      Here your HTML content
    </div>
    <button id="btnShow">Show me!</button>

    0 讨论(0)
  • 2020-11-29 15:42

    I find it more efficient, and more readable, to use the open event, and hide the title bar from there. I don't like using page-global class name searches.

    open: function() { $(this).closest(".ui-dialog").find(".ui-dialog-titlebar:first").hide(); }
    

    Simple.

    0 讨论(0)
提交回复
热议问题