用JS如何设定层的模式化 ,当点击一个按钮弹出层,并禁用页面。
展开全部
以下是我写的js代码可以实现你的要求,应该很简单吧
//半通明遮罩
document.writeln("<div id=\"divGg\" style=\"Z-INDEX:9999; LEFT:0px;POSITION:absolute; TOP:0px;display:none;background-color:#000;-moz-opacity: 0.3; opacity: 0.3; filter:alpha(opacity=30);\"></div>");
var divGg = document.getElementById("divGg");
//弹出层
document.writeln("<div id=\"divAdMsg\" style=\"Z-INDEX:99999; LEFT:0px;POSITION:absolute;height:307px; width:450px;display:none;background-color:#FFF;\"><a href=\"javascript:closeAdMsg();\" />关闭弹出层</a></div>");
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();
//半通明遮罩
document.writeln("<div id=\"divGg\" style=\"Z-INDEX:9999; LEFT:0px;POSITION:absolute; TOP:0px;display:none;background-color:#000;-moz-opacity: 0.3; opacity: 0.3; filter:alpha(opacity=30);\"></div>");
var divGg = document.getElementById("divGg");
//弹出层
document.writeln("<div id=\"divAdMsg\" style=\"Z-INDEX:99999; LEFT:0px;POSITION:absolute;height:307px; width:450px;display:none;background-color:#FFF;\"><a href=\"javascript:closeAdMsg();\" />关闭弹出层</a></div>");
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();
追问
能给个能运行出来的代码吗?
追答
无标题页
//半通明遮罩
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
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询