jQuery UI 是一个基于 jQuery 的一组用户界面交互、小部件和效果的库。弹出层(Dialog Widget)是 jQuery UI 中的一个小部件,用于创建模态或非模态对话框。
jQuery UI 弹出层在最顶层显示的问题通常是由于 z-index 属性设置不当导致的。z-index 属性决定了元素在页面上的堆叠顺序,数值越大,元素越靠上。
!important
强制设置 z-index。!important
强制设置 z-index。<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>jQuery UI Dialog Example</title>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<style>
/* 确保其他元素的 z-index 值不会干扰弹出层 */
.other-element {
z-index: 999;
}
</style>
</head>
<body>
<div id="dialog" title="Basic dialog">
<p>This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p>
</div>
<button id="open-dialog">Open Dialog</button>
<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.min.js"></script>
<script>
$(function() {
$("#dialog").dialog({
autoOpen: false,
modal: true,
zIndex: 1000 // 设置一个较高的 z-index 值
});
$("#open-dialog").click(function() {
$("#dialog").dialog("open");
});
});
</script>
</body>
</html>
通过上述方法,可以确保 jQuery UI 弹出层在最顶层显示。