用JS如何设定层的模式化 ,当点击一个按钮弹出层,并禁用页面。

2024-12-14 18:34:44
推荐回答(2个)
回答1:

以下是我写的js代码可以实现你的要求,应该很简单吧

//半通明遮罩
document.writeln("

");
var divGg = document.getElementById("divGg");
//弹出层
document.writeln("");
var divAdMsg = document.getElementById("divAdMsg");

//显示打开弹出层内容
function showAdMsg()
{
if(divAdMsg)
{
divAdMsg.style.display = "";
divAdMsg.style.top = document.documentElement.scrollTop + parseInt((document.documentElement.clientHeight - divAdMsg.offsetHeight) / 2) + "px";
divAdMsg.style.left = document.documentElement.scrollLeft + parseInt((document.documentElement.clientWidth - divAdMsg.offsetWidth) / 2) + "px";
divGg.style.width = document.body.offsetWidth + "px";
if(document.body.offsetHeight < document.documentElement.scrollTop + document.documentElement.clientHeight)
divGg.style.height = document.documentElement.scrollTop + document.documentElement.clientHeight + "px";
else
divGg.style.height = document.body.offsetHeight + "px";
divGg.style.display = "";
}
}
//关闭打开弹出层内容
function closeAdMsg()
{
divAdMsg.style.display = "none";
divGg.style.display = "none";
}
showAdMsg();

回答2:

添加两个层,一个作为阴影层,一个作为弹出层