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

[亡魂溺海] 提交于 2019-12-20 17:14:59

【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>>

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


#1楼

一旦在元素上调用.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>

演示在这里


#2楼

Robert MacLean的回答对我不起作用。

但这对我有用:

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

#3楼

您还可以删除标题行:

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

删除关闭按钮。


#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" );
        }
    }]
});
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!