我看了一个通宵都没有看出错误的代码,有谁帮帮我呀?
  代码如下:
    function divshow()
    {
     
         if(document.getElementById("divFunction").style.display=="none")
         {
            //alert("asdfadsfasd");
            document.getElementById("divFunction").style.display="block";
            document.getElementById("divFunction1").style.display="block";
            document.getElementById("divFunction0").style.display="block";          
            //让弹出层在页面中垂直左右居中
        //var arrayPageSize = getPageSize();
        //var arrayPageScroll = getPageScroll();
        //alert(arrayPageScroll);
        //alert(arrayPageSize);
        
        document.getElementById("divFunction").style.width = "100%";
        //document.getElementById("divFunction").style.height = "5000" + "px";
        document.getElementById("divFunction").style.height = "100%";
        document.getElementById("divFunction").style.zIndex = "998";
        document.getElementById("divFunction").style.position = "absolute";
        document.getElementById("divFunction").style.top = "0";
        document.getElementById("divFunction").style.left = "0";
        document.getElementById("divFunction").style.filter = "alpha(opacity=10)";
        document.getElementById("divFunction").style.opacity = "0.80";   
        document.getElementById("divFunction").style.color="#6ba7e6";
        document.getElementById("divFunction").style.backgroundColor = "#666666";
        document.getElementById("divFunction").style.textAlign = "center";
        
//         document.getElementById("divFunction1").style.width = document.getElementById("gvFunction").offsetWidth + 30 + 'px';
//         document.getElementById("divFunction1").style.height = document.getElementById("gvFunction").offsetHeight + 30 + 'px';
        document.getElementById("divFunction1").style.width = "398px"
        document.getElementById("divFunction1").style.height = "330px"
        document.getElementById("divFunction1").style.zIndex = "1000";
        document.getElementById("divFunction1").style.position = "absolute";
        document.getElementById("divFunction1").style.left="30.8%";
        document.getElementById("divFunction1").style.top="10%";
        document.getElementById("divFunction1").style.padding = "0px";
        document.getElementById("divFunction1").style.backgroundColor="#ffffff";
        document.getElementById("divFunction1").style.border="0px solid #bdbdbd";
        document.getElementById("divFunction1").style.textAlign = "center";
        //document.getElementById("tbTLT_Card_Id").focus();
            //document.getElementById("tbTLT_Card_Id").select();
        
         //设置前面透明层
            document.getElementById("divFunction0").style.width = "418px"
        document.getElementById("divFunction0").style.height = "346px"
        document.getElementById("divFunction0").style.zIndex = "999"; //定位元素的顺序
        document.getElementById("divFunction0").style.position = "absolute"; //设置元素的定位方式
        document.getElementById("divFunction0").style.top = "9%" 
        document.getElementById("divFunction0").style.left = "30%";
        document.getElementById("divFunction0").style.filter = "alpha(opacity=40)"; //设置背景透明
        document.getElementById("divFunction0").style.opacity = "0.80"; 
        document.getElementById("divFunction0").style.color="#6ba7e6";
        document.getElementById("divFunction0").style.backgroundColor = "#7a7a7a";
        document.getElementById("divFunction0").style.textAlign = "center";
        
         }
         else
         {    
            document.getElementById("divFunction").style.display="none";
            document.getElementById("divFunction1").style.display="none";
            document.getElementById("divFunction0").style.display="none";
         }
    }  是个弹出div层,不知为什么当点击按钮时,div就跑到了最顶层,且后面的遮罩层只显示一半。
  

解决方案 »

  1.   

    没html不好分析,这里有个弹出层的,你也可以参考<script type="text/javascript">
        var docEle = function()
        {
            return document.getElementById(arguments[0]) || false;
        }    function openNewDiv(_id)
        {
            var m = "mask";
            if (docEle(_id)) document.body.removeChild(docEle(_id));
            if (docEle(m)) document.body.removeChild(docEle(m));        //mask遮罩层        var newMask = document.createElement("div");
            newMask.id = m;
            newMask.style.position = "absolute";
            newMask.style.zIndex = "1";
            _scrollWidth = Math.max(document.body.scrollWidth,document.documentElement.scrollWidth);
            _scrollHeight = Math.max(document.body.scrollHeight,document.documentElement.scrollHeight);
            newMask.style.width = _scrollWidth + "px";
            newMask.style.height = _scrollHeight + "px";
            newMask.style.top = "0px";
            newMask.style.left = "0px";
            newMask.style.background = "#33393C";
            newMask.style.filter = "alpha(opacity=40)";
            newMask.style.opacity = "0.40";
            document.body.appendChild(newMask);        //新弹出层        var newDiv = document.createElement("div");
            newDiv.id = _id;
            newDiv.style.position = "absolute";
            newDiv.style.zIndex = "9999";
            newDivWidth = 400;
            newDivHeight = 200;
            newDiv.style.width = newDivWidth + "px";
            newDiv.style.height = newDivHeight + "px";
            newDiv.style.top = (document.body.scrollTop + document.body.clientHeight/2 - newDivHeight/2) + "px";
            newDiv.style.left = (document.body.scrollLeft + document.body.clientWidth/2 - newDivWidth/2) + "px";
            newDiv.style.background = "#EFEFEF";
            newDiv.style.border = "1px solid #860001";
            newDiv.style.padding = "5px";
            newDiv.innerHTML = " ";
            document.body.appendChild(newDiv);        //弹出层滚动居中        function newDivCenter()
            {
                newDiv.style.top = (document.body.scrollTop + document.body.clientHeight/2 - newDivHeight/2) + "px";
                newDiv.style.left = (document.body.scrollLeft + document.body.clientWidth/2 - newDivWidth/2) + "px";
            }
            if(document.all)
            {
                window.attachEvent("onscroll",newDivCenter);
            }
            else
            {
                window.addEventListener('scroll',newDivCenter,false);
            }        //关闭新图层和mask遮罩层
            var newA = document.createElement("div");
            newA.innerHTML ="关闭";
            newA.onclick = function(){
                if(document.all)
                {
                    window.detachEvent("onscroll",newDivCenter);
                }
                else
                {
                    window.removeEventListener('scroll',newDivCenter,false);
                }
                document.body.removeChild(docEle(_id));
                document.body.removeChild(docEle(m));
                return false;
            }
            newDiv.appendChild(newA);
        }
    </script>
    <body>    <a onclick="openNewDiv('newDiv');return false;" style="cursor:pointer">弹出层</a>
    </body>
      

  2.   

    我也给你发个简单的吧<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>弹出提示</title>
    <style>
    * {margin:0;padding:0;font-size:12px;}
    html,body {height:100%;width:100%;}
    #content {background:#f8f8f8;padding:30px;height:100%;}
    #content a {font-size:30px;color:#369;font-weight:700;}
    #alert {border:1px solid #369;width:300px;height:150px;background:#e2ecf5;z-index:1000;position:absolute;display:none;}
    #alert h4 {height:20px;background:#369;color:#fff;padding:5px 0 0 5px;}
    #alert h4 span {float:left;}
    #alert h4 span#close {margin-left:210px;font-weight:500;cursor:pointer;}
    #alert p {padding:12px 0 0 30px;}
    #alert p input {width:120px;margin-left:20px;}
    #alert p input.myinp {border:1px solid #ccc;height:16px;}
    #alert p input.sub {width:60px;margin-left:30px;}
    </style>
    </head>
    <body>
    <div id="content">
    <a href="#">注册</a>
    </div><a href="#">dd</a>
    <div id="alert">
    <h4><span>现在注册</span><span id="close">关闭</span></h4>
    <p><label>用户名</label><input type="text" class="myinp" onmouseover="this.style.border='1px solid #f60'" onfoucs="this.style.border='1px solid #f60'" onblur="this.style.border='1px solid #ccc'" /></p>
    <p><label>密 码</label><input type="password" class="myinp" onmouseover="this.style.border='1px solid #f60'" onfoucs="this.style.border='1px solid #f60'" onblur="this.style.border='1px solid #ccc'" /></p>
    <p><input type="submit" value="注册" class="sub" /><input type="reset" value="重置" class="sub" /></p>
    </div>
    <script type="text/javascript">var myAlert = document.getElementById("alert");
    var reg = document.getElementById("content").getElementsByTagName("a")[0];
    var mClose = document.getElementById("close");
    reg.onclick = function()
    {mybg = document.createElement("div");
    mybg.setAttribute("id","mybg");
    mybg.style.background = "#000000";
    mybg.style.width = "100%";
    mybg.style.height = "100%";
    mybg.style.position = "absolute";
    mybg.style.top = "0";
    mybg.style.left = "0";
    mybg.style.zIndex = "10";
    mybg.style.filter = "Alpha(opacity=0)";
    document.body.appendChild(mybg);
    myAlert.style.display = "block";
    myAlert.style.position = "absolute";
    myAlert.style.top = "50%";
    myAlert.style.left = "50%";
    myAlert.style.marginTop = "-75px";
    myAlert.style.marginLeft = "-150px";
    }
    mClose.onclick = function()
    {
    myAlert.style.display = "none";
    mybg.style.display = "none";
    }
    </script></body>
    </html>