如何删除jQuery UI对话框上的关闭按钮?

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


#1楼

一旦在元素上调用.dialog() ,就能够在任何方便的时间找到关闭按钮(和其余对话框标记),而无需使用事件处理程序: ui

$("#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指的是“对话”元素和$(this).parent()引用对话框标记容器,所以: spa

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

仅供参考,对话框标记以下所示: code

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

演示在这里 事件


#2楼

Robert MacLean的回答对我不起做用。 element

但这对我有用: rem

$("#div").dialog({
   open: function() { $(".ui-dialog-titlebar-close").hide(); }
});

#3楼

您还能够删除标题行: get

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

删除关闭按钮。


#4楼

Dialog小部件添加的关闭按钮具备类'ui-dialog-titlebar-close',所以在初始调用.dialog()以后,您能够使用这样的语句再次删除关闭按钮:它能够工做..

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

#5楼

如官方页面所示并由David建议:

建立一个样式:

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

而后,您能够简单地将no-close类添加到任何对话框,以隐藏它的关闭按钮:

$( "#dialog" ).dialog({
    dialogClass: "no-close",
    buttons: [{
        text: "OK",
        click: function() {
            $( this ).dialog( "close" );
        }
    }]
});
相关文章
相关标签/搜索