jQuery对话框(通常指jQuery UI Dialog)是一个模态窗口组件,用于在页面上显示交互式内容。标题栏是对话框的默认组成部分,显示在对话框顶部。
$("#dialog").dialog({
title: "", // 设置空标题
create: function(event, ui) {
// 隐藏标题栏
$(this).parent().find(".ui-dialog-titlebar").hide();
}
});
.ui-dialog-titlebar {
display: none !important;
}
$("#dialog").dialog({
dialogClass: "no-title-dialog" // 自定义类名
});
然后添加CSS:
.no-title-dialog .ui-dialog-titlebar {
display: none;
}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<style>
.no-title .ui-dialog-titlebar {
display: none;
}
</style>
</head>
<body>
<div id="dialog" title="默认标题">
<p>这是一个没有标题栏的对话框</p>
</div>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script>
$(function() {
$("#dialog").dialog({
dialogClass: "no-title",
buttons: {
"关闭": function() {
$(this).dialog("close");
}
}
});
});
</script>
</body>
</html>