JS+CSS实现带关闭按钮的DIV弹出窗口

作者:页面旅途

时间:2026-10-28

浏览:559

本文介绍如何使用JavaScript和CSS实现一个带有关闭按钮的DIV弹出窗口。通过简单的代码示例,展示了如何创建弹出层、设置遮罩层以及添加关闭功能,适合前端开发者参考学习。

文章目录

JS+CSS实现带关闭按钮的DIV弹出窗口

本文通过具体实例,详细讲解了利用JavaScript和CSS技术实现带有关闭按钮的DIV弹出窗口的方法。该方案旨在为开发者提供实用的参考,帮助其快速掌握相关实现技巧。

以下是完整的实现代码示例:

<html>
<head>
<title>JS+CSS实现带关闭按钮的DIV弹出窗口</title>
<script>
function locking(){
document.all.ly.style.display="block";
document.all.ly.style.width=document.body.clientWidth;
document.all.ly.style.height=document.body.clientHeight;
document.all.Layer2.style.display='block';
   }   
function Lock_CheckForm(theForm){
document.all.ly.style.display='none';document.all.Layer2.style.display='none';
return false;
   }   
</script>
<style type="text/css">
<!--
.STYLE1 {font-size: 12px}
a:link {
color: #FFFFFF;
text-decoration: none;
}
a:visited {
text-decoration: none;
}
a:hover {
text-decoration: none;
}
a:active {
text-decoration: none;
}
-->
</style>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<p align="center">
<input type="button" value="弹出DIV" onClick="locking()" />
</p>
<div id="ly" style="position: absolute; top: 0px; filter: alpha(opacity=60); background-color: #777;
z-index: 2; left: 0px; display: none;">
</div>
<!-- 浮层框架开始 -->
<div id="Layer2" align="center" style="position: absolute; z-index: 3; left: expression((document.body.offsetWidth-540)/2); top: expression((document.body.offsetHeight-170)/10);
background-color: #fff; display: none;" >
<table width="540" height="300" border="0" cellpadding="0" cellspacing="0" style="border: 0 solid #e7e3e7;
border-collapse: collapse ;" >
<tr>
<td style="background-color: #73A2d6; color: #fff; padding-left: 4px; padding-top: 2px;
font-weight: bold; font-size: 12px;" height="10" valign="middle">
<div align="right"><a href=JavaScript:; class="STYLE1" onclick="Lock_CheckForm(this);">[关闭]</a> &nbsp;&nbsp;&nbsp;&nbsp;</div></td>
</tr>
<tr>
<td height="130" align="center">
</td>
</tr>
</table>
</div>
<!-- 浮层框架结束-->
</body>
</html>

希望本文所述内容能对各位在JavaScript程序设计方面提供有益的帮助。

实用工具推荐

电子包浆

绿化、压缩、噪点和虚拟水印,自由调节做旧程度。

使用 ›
图片压缩

选择画质和输出格式,预览压缩前后的大小。

使用 ›
相关文章