我想移除jQuery对话框的标题栏,但我想保留关闭(叉)按钮。
我找到了这个问题:
jquery UI dialog: how to initialize without a title bar?
那里的答案解释了如何移除标题栏,但如果我这样做,它也会移除关闭按钮。还有其他链接,但它们都是一样的。他们只是隐藏整个标题栏以及关闭按钮。
我想移除jQuery对话框的标题栏,但我想保留关闭(叉)按钮。
我找到了这个问题:
jquery UI dialog: how to initialize without a title bar?
那里的答案解释了如何移除标题栏,但如果我这样做,它也会移除关闭按钮。还有其他链接,但它们都是一样的。他们只是隐藏整个标题栏以及关闭按钮。
$(function() {
$( "#dialog" ).dialog();
$("#ui-dialog-title-dialog").hide();
$(".ui-dialog-titlebar").removeClass('ui-widget-header');
});
对于 jQuery UI 的新版本,版本号要大于 1.10.3
$("#dialog .ui-dialog-titlebar").css({
"background-color" : "transparent",
"border" : "0px none"
});
ui-widget-header
类。 - Tomas$(function() {
$( "#dialog" ).dialog();
$(".ui-dialog-titlebar").removeClass('ui-widget-header');
});
.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:
var closeDiv = document.createElement("div");
closeDiv.className = "CloseButton";
JS:
$(closeDiv).click(function () {
$("yourDialogContent").dialog('close');
});
我认为最简单和最健壮的解决方案(其他方案在1.10.3版本中无法工作,因为它们假定可以更改的内容)是直接设置所期望的CSS样式。
$("#dialog .ui-dialog-titlebar").css({
"background-color" : "transparent",
"border" : "0px none"
});
我尝试了其他建议更改background-color
属性的解决方案,但都没有帮助。对我来说,解决方案是将background
属性更改为透明。
.ui-dialog-titlebar {
background: transparent;
border: 0 none;
}