简体   繁体   English

jQuery UI对话框没有标题栏但保留关闭按钮

[英]jQuery UI dialog without a title bar but keep the close button

I want to remove the titelbar of the jQuery dialog. 我想删除jQuery对话框的titelbar。 But I want to keep the close (cross) button there. 但我想保持关闭(交叉)按钮。

I found this question: 我发现了这个问题:

jquery UI dialog: how to initialize without a title bar? jquery UI对话框:如何在没有标题栏的情况下初始化?

The answers there explains how to remove titlebar, but if I do that it also removes the close button. 那里的答案解释了如何删除标题栏,但如果我这样做,它也会删除关闭按钮。 There are other links too but they all do the same. 还有其他链接,但他们都做同样的事情。 They just hide the whole titlebar along with the close button. 他们只是隐藏整个标题栏和关闭按钮。

Is there any solution that hides the title bar while keeping the close button? 是否有任何解决方案隐藏标题栏同时保持关闭按钮?

Use this to remove the titelbar of the jQuery dialog and not the close button 使用它来删除jQuery对话框的titelbar而不是关闭按钮

 $(function() {
    $( "#dialog" ).dialog();
    $("#ui-dialog-title-dialog").hide();
    $(".ui-dialog-titlebar").removeClass('ui-widget-header');
 });

for newer version jquery UI > 1.10.3 对于较新版本的jquery UI> 1.10.3

$("#dialog .ui-dialog-titlebar").css({ 
     "background-color" : "transparent", 
     "border" : "0px none" 
});

This works too 这也有效

$(function() {
$( "#dialog" ).dialog();
$(".ui-dialog-titlebar").removeClass('ui-widget-header');
});

You could remove the bar with the close icon with the techinques described above and then add a close icon yourself. 您可以使用上述技术的关闭图标删除栏,然后自己添加一个关闭图标。

CSS: CSS:

.CloseButton {
background: url('../icons/close-button.png');   
width:15px;
height:15px;
border: 0px solid white;
top:0;
right:0;
position:absolute;
cursor: pointer;
z-index:999;
}

HTML: HTML:

var closeDiv = document.createElement("div");
closeDiv.className = "CloseButton";

//append this div to the div holding your content //将此div附加到包含您内容的div

JS: JS:

 $(closeDiv).click(function () {
         $("yourDialogContent").dialog('close');
     });

I think the easiest and most robust solution (the other ones here do not work for 1.10.3 since they assume things that can change") is to directly set the CSS style for it that you expect it to have. 我认为最简单,最强大的解决方案(这里的其他解决方案不适用于1.10.3,因为它们假定可以改变的东西“)是直接为它设置的CSS样式。

$("#dialog .ui-dialog-titlebar").css({ 
     "background-color" : "transparent", 
     "border" : "0px none" 
});

I tried the other solutions here that suggested changing the background-color attribute and that did not help. 我尝试了其他解决方案,建议更改background-color属性,这没有帮助。 The solution for me was changing the background attribute to transparent. 我的解决方案是将background属性更改为透明。

.ui-dialog-titlebar { background: transparent; border: 0 none; }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM