jsp通过div实现覆盖,弹出新窗体

这篇博客介绍如何利用jsp和div实现一个点击按钮后弹出覆盖全屏的窗体效果。通过示例代码展示了如何设置div的样式、事件监听以及JavaScript函数来控制显示和关闭覆盖层。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<body style="height:100%;">

-------------------------------------------------------------------一开始的页面----------------------

fdasfsdfadf

<input name="button2" onclick="ShopConfirm('fdsaf')" value="点我" type="button"/>

----------------------------------------------------------点击后出现的覆盖显示的内容-------------------
<!--内容层-->
<div id="ShopConfirmLayer" style="position:absolute;top:300px;left:100px;z-index:900;border:1px red solid;width:500px;display:none;">

这是我点击后出现的内容

    <input name="button1" value="关闭" type="button" onclick="CloseShopConfirm()"/>
</div>

------------------------------------------------------------------覆盖的页面-------------------
<!--覆盖层-->
<div id="webBgLayer" style="position:absolute;top:0px;left:0px;z-index:899;background-color:#ccc;height:100%;width:100%;display:none;-moz-opacity:0.9;filter:alpha(opacity=50);"></div>

 

                              -------------------这里;-moz-opacity:0.9;filter:alpha(opacity=50)很关键/*透明滤镜50%*/ }

 


<script type="text/javascript">
    function ShopConfirm(str){
        var ShopConfirmLayer=document.getElementById("ShopConfirmLayer");
        var webBgLayer=document.getElementById("webBgLayer");
     // ShopConfirmLayer.innerHTML=str;
         ShopConfirmLayer.style.display="";//显示内容层,显示覆盖层

     ShopConfirmLayer.style.left=parseInt((document.documentElement.scrollWidth-ShopConfirmLayer.offsetWidth)/2)+document.documentElement.scrollLeft+"px";
     ShopConfirmLayer.style.top=Math.abs(parseInt((document.documentElement.clientHeight-ShopConfirmLayer.offsetHeight)/2))+document.documentElement.scrollTop+"px"; //为内容层设置位置


     webBgLayer.style.display="";
     webBgLayer.style.height=document.documentElement.scrollHeight+"px"; //为覆盖层设置高度 
    }
    function CloseShopConfirm(){
        var ShopConfirmLayer=document.getElementById("ShopConfirmLayer");
        var webBgLayer=document.getElementById("webBgLayer");
        ShopConfirmLayer.style.display="none"; 
        webBgLayer.style.display="none";
    }
</script>
</body>

 

 

代码还是比较简单的认真学习吧~~ 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值